Reputation: 2153
I have a masterPage with a variable. I know how to use the variable on childPage with masterType. But I search how to get the variable inside a usercontrol (the control is on childPage)?
Maybe the childPage need to pass a "pointer" of the masterPage to the usercontrol?
I try to use MasterType on my usercontrol but
'Master' is not a member of 'System.Web.UI.UserControl
On designer.vb
Public Shadows ReadOnly Property Master() As MasterTypeName
Get
Return CType(MyBase.Master, MasterTypeName)
End Get
End Property
Is there a way that MasterType is know by the userControl?
Upvotes: 0
Views: 180
Reputation: 3615
Instead of trying to figure out how to get a value from the master page to the control, why not use the control as it is intended? Controls are meant to be able to be independent of the pages (and master pages) they reside on. Instead, create a publicly accessible property in your user control that can be set by the child page. For example, if you had this in your user control:
''' <summary>
'''Some summary to show in the properties window
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<Description("Your description here")> Public Property someValue As String = "something"
You can then access that property in either in the client code of where it resides or in the code behind. For example:
<cc3:myControl ID='myCOntrol1' runat="server" someProperty="HelloWorld"/>
or in codebehind:
myControl1.someProperty ="HelloWorld"
You can also expose events in a similar manner.
Let me know if this helps or if there is a reason this would not work for you.
Upvotes: 1