Steps to reference master page properties from content page - Master Pages

Q.  What are the basic steps to reference master page properties from a content page?

- Published on 27 Jul 15

a.
- Create a property in the master page code-behind file.
- Reference the master page property from the content page using the syntax Master.<Property_Name>
b.
- Create a property in the master page code-behind file.
- Add the @ MasterType declaration to the .aspx content page.
- Reference the master page property from the content page using the syntax Master.<Property_Name>
c.
- Create a property in the master page code-behind file.
- Reference the master page property from the content page using the syntax Master.<Property_Name>
d. None of the above

ANSWER:
- Create a property in the master page code-behind file.
- Add the @ MasterType declaration to the .aspx content page.
- Reference the master page property from the content page using the syntax Master.<Property_Name>
 

    Discussion

  • ramesh   -Posted on 01 Oct 15
    Creating a Property in the Master Page

    // txtWebSiteName is the ID of TextBox in Master Page

    public String WebSiteName
    {

    get { return txtWebSiteName.Text; }

    set { txtWebSiteName.Text = value; }

    }

    Connecting to Master Page Properties from Content Pages

    You must add the @ MasterType declaration to the .aspx content page to reference master properties in a content page.

    <%@ MasterType VirtualPath="~/YourMasterPageName.master" %>
    Now you can reference properties in the master page using the Master class.

    Lable1.Text=Master.WebSiteName

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)