Master Pages

Hi

Long time since I posted an article on my blog!
I have been reading more about Master Pages in ASP.NET and I think it is a cool feature to have when you have the same structure across multiple pages.

One new(probably for me) thing I learnt is about
<%@ MasterType %> Attribute.

This attribute will be used in the web pages(.aspx) and is used to call the properties that are defined in the master page via Master. call.

Say for example: If we have a property to which gets or sets a boolean value in the master page(Site.Master):

private _setFlag= false;
public bool setFlag
{
get{return _setFlag;}
set{_setFlag=value;}
}

In the web page Page1.aspx if we want to call the property of the master page, we could achieve this by using the following attribute:

<%@MasterType VirtualPath="Site.Master"%>

public void Page_PreInit(object sender, EventArgs e)
{
Response.Write(Master.setFlag.ToString());
}

Comments

Popular posts from this blog

Knowing too much is bad(in the world of OOP)

Reverse a LinkedList Algorithm

DateTime.Now in C#