Add/Remove master page control from child page in asp.net

Most of the time, developers who are new to .NET encounter this problem of handling or setting master page control properties from their child pages/content pages.

The below technique can be used to set various properties of the master page controls like :
1) Show/hide master page controls if for some of its child page that control need not be displayed.
2) Remove master page control from child page
etc…

Technique:

In the master page, server side i.e vb.net make a public property and its getter setter methods as follows:

Public Property ShowHideControl() As String
        Get
            Return Control1.display
        End Get
        Set(ByVal value As String)
            Control1.display = value
        End Set
End Property

where Control1 is a master page control/element id.

Now, in any of this master page’s child page if you want to hide Control1 element, then you just need to write the below code in child page’s Page_Load() function in aspx.vb file:

Master.ShowHideControl= “None”

This will hide the Control1 from that specific child page.

If somewhere you want to get the property value of Control1 to see whether its hidden or shown, you can use its get property function as:

Master.ShowHideControl

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>