Page 155 - DCAP312_WEB_TECHNOLOGIES_II
P. 155
Unit 8: Creating More Advanced ASP.NET
{ Notes
}
}
Note that we need to add the Page_Load method in the Parent Page.cs to
the loading event handler so that the method will get called when the page
loads.
Now we just need to use the User Name in either of our pages, even though
it is a protected member of Parent Page, the pages that subclass from that
page can reach the member. However, other objects can modify User Name.
This we get from inheritance.
ParentPage.cs
public class ParentPage : System.Web.UI.Page
{
protected String _UserName;
protected override void OnInit(EventArgs e)
{
//WWB: Allow The Base Class To Intialize First
base.OnInit(e);
UserName = Session[ “UserName”].ToString();
}
}
page1.aspx.cs
public partial class Page1 : ParentPage
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(_UserName);
}
}
{
ParentMasterPage.cs
public class ParentMasterPage : System.Web.UI.MasterPage
{
protected String _title;
public ParentMasterPage()
{
}
public void SetTitle(String title)
{
title = title;
}
}
ParentPage.cs
public class ParentPage : System.Web.UI.Page
{
protected String _UserName;
LOVELY PROFESSIONAL UNIVERSITY 149