Bunch's Blog

One day I'll have a catchy subtitle, one day
posts - 83, comments - 94, trackbacks - 0

My Links

News

Tag Cloud

Archives

Green

Accessing Master Page Controls

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: ,

Print | posted on Thursday, April 08, 2010 2:23 PM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: