Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I have two master pages SiteMaster.Master and HomeMaster.Master and content Pages MyAccount.aspx with HomeMaster.Master and MyDashboard.aspx with SiteMaster.Master with PageBase class. In this SiteMaster.Master is Main master page and HomeMaster.Master is nested Master page which is having SiteMaster.Master page as Master Page.

Now, In SiteMaster.Master page is having a label called lblMasterDate which shows current date. for this, label I want to assign values dynamically from pagebase.
In PageBase to find lblMasterDate I used:

Label MasterPageDate = this.Master.Master.FindControl("lblMasterPageDate") as Label;
MasterPageDate.Text = DateTime.Now.DayOfWeek.ToString() + " | " + DateTime.Now.ToString(aDateFormat) + " | " + DateTime.Now.ToShortTimeString();


This statement throws exception when I access MyDashboard.aspx .
Can anyone please help me to solve this problem.

Thanks In Advance.
-Sindhu.A
Posted

Write this way

(this.Page.Master.Master.FindControl("lblMasterPageDate") as Label).Text = DateTime.Now.DayOfWeek.ToString() + " | " + DateTime.Now.ToString(aDateFormat) + " | " + DateTime.Now.ToShortTimeString();
 
Share this answer
 
Hi,

Try this:
C#
Label MasterPageDate = Parent.Parent.FindControl("lblMasterPageDate") as Label;
MasterPageDate.Text = DateTime.Now.DayOfWeek.ToString() + " | " + DateTime.Now.ToString(aDateFormat) + " | " + DateTime.Now.ToShortTimeString();




--Amit
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900