Question Can I pass a value from ascx to aspx?

Rad

Member
Joined
Feb 26, 2009
Messages
8
Programming Experience
5-10
I have a Menus user control and depending on which menu item the User clicks, the appropriate page is loaded by setting the hyperlink.NavigateUrl to the appropriate aspx page.
I need to use the same page for 2 different menu items but I need to pass a value to the page so I know which data to load into it.
Is there a way to pass the menu name or any other value from the usercontrol to the asp.net page?
 
Yes, there are many ways you can collect and store data between your user controls.
One thing you could do is to have Public Properties on your user control and set them either via the editor (<myCtrl:whatever runat="server" id="myControl" Property1="whatever" Property2="whatever" />) or via code:

VB.NET:
Expand Collapse Copy
Protected Sub OnPageLoad('variables) handles me.Load
If not Page.IsPostBack Then
myControl.Property1 = "whatever"
myControl.Property2 = "whatever"
End If
End Sub

note: I wrote that code on the forums and havent tested it, but you should get the general idea.
 
Back
Top