Wednesday, September 22, 2010

Event Sequence oF Master & Content Pages.

Master and Content Page Event Sequence.

1. Content Page: Page_PreInit event.
2. Master page : Page_Init event
3. Content Page :Page_Init event
4. Content Page : Page_Load event
6. Master Page : Page_Load event
7. Content Page: Page_PreRender event
8. Master Page : Page_PreRender event
9. Master Page: Page_UnLoad event
10. Content Page: Page_UnLoad event

Sample Code :
Step 1.Create a Master Page say Parent_MasterPage and write the below code on Code behind file(.cs file )
Parent_MasterPage.cs
public partial class Parent_MasterPage : System.Web.UI.MasterPage
{

protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Master_Page_Load;" );
}
protected void Page_Init(object sender, EventArgs e)
{
Response.Write("Master_Page_Init;" );
}
protected void Page_PreInit(object sender, EventArgs e)
{
Response.Write("Master_Page_PreInit;" );
}
protected void Page_UnLoad(object sender, EventArgs e)
{
//Response.Write("Master_Page_UnLoad");
}
protected void Page_PreRender(object sender, EventArgs e)
{
Response.Write("Master_Page_PreRender ;" );
}
protected void Page_Render(object sender, EventArgs e)
{
Response.Write("Master_Page_Render ;" );
}
}
Step 2.Create a Content Page say Default.aspx and write the below code on Code behind file(.cs file )
Default.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Code writtent for accessing the Control of Master page in Content pages
Label lbl = new Label();
lbl = (Label)Master.FindControl("Label1");
lbl.Text = "Lable Control of Master page is accessed in Content page and its value get changed.";

Response.Write( "Content_Page_Load;" );

}
protected void Page_Init(object sender, EventArgs e)
{
Response.Write("Content_Page_Init;");
}
protected void Page_PreInit(object sender, EventArgs e)
{

Response.Write("Content_Page_PreInit;" );

}
protected void Page_UnLoad(object sender, EventArgs e)
{
//Response.Write("Content_Page_UnLoad");
}
protected void Page_PreRender(object sender, EventArgs e)
{
Response.Write( "Content_Page_PreRender;");

}
protected void Page_Render(object sender, EventArgs e)
{
Response.Write ( "Content_Page_Render;" );

}
}

No comments: