Access Master Pages Properties

There are different techniques to access MasterPages properties

Master Page
Code file:

public partial class MyMasterPageClass: System.Web.UI.MasterPage
{
public string ErrorMessage
{
set
{
lblErrorPane.Text = value;
panelErrorMessage.Visible = true;
}
}
}


Content Page

1) ((MyMasterPageClass)Master).ErrorMessage = " Test Error Message";


After adding this <%@ MasterType VirtualPath="~/MasterPage.master" %> under Page Directive you can access the property of master page directly.

2) this.Master.ErrorMessage = "Test Message";

Comments

Popular posts from this blog

Use configSource attribute to manage Web.Config sections in ASP.Net 2.0

DevOps - Key Concepts - Roles & Responsibilities - Tools & Technologies