Accessing Master Page Controls
Posted
by Bunch
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Bunch
Published on Thu, 08 Apr 2010 12:23:59 GMT
Indexed on
2010/04/08
18:43 UTC
Read the original article
Hit count: 199
Sometimes when using Master Pages you need to set a property on a control from the content page. An example might be changing a label’s text to reflect some content (e.g. customer name) being viewed or maybe to change the visibility of a control depending on the rights a user may have in the application. There are different ways to do this but this is the one I like.
First on the code behind of the Master Page create the property that needs to be accessed. An example would be:
Public Property CustomerNameText() As String
Get
Return lblCustomerName.Text
End Get
Set(ByVal value As String)
lblCustomerName.Text = value
End Set
End Property
Next in the aspx file of the content page add the MasterType directive like:
<%@ MasterType VirtualPath="~/MasterPages/Sales.master" %>
Then you can access the property in any of the functions of the code behind of the aspx content page.
Master.CustomerNameText = “ABC Store”
© Geeks with Blogs or respective owner