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

M

Matt Hawley

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
 
J

Jos

Andre said:
And how do I do that when I load the control programmatically like
this:

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

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

Fred Hirschfeld

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

Matt Hawley said:
Hi Andre,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top