Geeks With Blogs
Bunch's Blog One day I'll have a catchy subtitle, one day

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”

Technorati Tags: ,
Posted on Thursday, April 8, 2010 2:23 PM | Back to top


Comments on this post: Accessing Master Page Controls

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Bunch | Powered by: GeeksWithBlogs.net