在内容页面中检索嵌套的母版页标签 [英] Retrieve Nested Master Page Label in content page

查看:70
本文介绍了在内容页面中检索嵌套的母版页标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有两个母版页SiteMaster.Master和HomeMaster.Master,以及内容页MyAccount.aspx(带有HomeMaster.Master)和MyDashboard.aspx(带有SiteMaster.Master,带有PageBase类).在此SiteMaster.Master中是Main母版页,而HomeMaster.Master是嵌套的Master页,其中将SiteMaster.Master页作为Master页.

现在,在SiteMaster.Master页面中有一个名为lblMasterDate的标签,用于显示当前日期.为此,标签我想从页面库动态分配值.
在PageBase中找到我使用的lblMasterDate:

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();



当我访问MyDashboard.aspx时,此语句引发异常.
谁能帮我解决这个问题.

在此先感谢.
-Sindhu.A



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

Thanks In Advance.
-Sindhu.A

推荐答案

以这种方式编写

(this.Page.Master.Master.FindControl("lblMasterPageDate")作为Label).Text = DateTime.Now.DayOfWeek.ToString()+"|" + DateTime.Now.ToString(aDateFormat)+"|" + DateTime. Now.ToShortTimeString();
Write this way

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




试试这个:
Hi,

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





--Amit





--Amit


这篇关于在内容页面中检索嵌套的母版页标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆