all groups > asp.net building controls > april 2004 >
You're in the

asp.net building controls

group:

how to pass on a variable from a page to a user control / best practice


how to pass on a variable from a page to a user control / best practice Matt Hawley
4/23/2004 7:59:34 AM
asp.net building controls:
Hi Andre,

The preferred method for handling this, is by creating public properties in your user control that you can set via code.

Matt Hawley, MCAD .NET
http://www.eworldui.net

I have a general question what the best practice is passing along values
from an aspx-page to a user-control.

Let's say I call an aspx page like this: myaspxpage.aspx?id=5.

On that page I use Request.Params to store the id value in a variable.
But i also need that id value in the user-control.

So do I have to call Request.Params again in the usercontrol
or should I transfer the value over from the main page.

Or is there another different / better solution

Thanks in advance

Andre


how to pass on a variable from a page to a user control / best practice Andre Beier
4/23/2004 9:36:14 AM
I have a general question what the best practice is passing along values
from an aspx-page to a user-control.

Let's say I call an aspx page like this: myaspxpage.aspx?id=5.

On that page I use Request.Params to store the id value in a variable.
But i also need that id value in the user-control.

So do I have to call Request.Params again in the usercontrol
or should I transfer the value over from the main page.

Or is there another different / better solution

Thanks in advance

Andre

Re: how to pass on a variable from a page to a user control / best practice Andre Beier
4/23/2004 10:28:32 AM
And how do I do that when I load the control programmatically like this:

MainPane.Controls.Add(Page.LoadControl("reportPerformance.ascx"))


[quoted text, click to view]

Re: how to pass on a variable from a page to a user control / best practice Jos
4/24/2004 2:06:15 PM
[quoted text, click to view]

Dim myControl = Page.LoadControl("reportPerformance.ascx")
myControl.myIDProperty = Request.GetString("id")
MainPane.Controls.Add(myControl)

--

Jos

Re: how to pass on a variable from a page to a user control / best practice Fred Hirschfeld
4/25/2004 8:43:04 AM
But I prefer to just use the Page.Request.Params[..] within the user control
to minimize the amount of extra code in the page. I would only do this if
the control from the client posting the information was generated from the
user control.

If you are trying to use a value from some other control, then I would
follow the other recommendations posted here and use a property.

Fred

[quoted text, click to view]

AddThis Social Bookmark Button