[英]Change Label.Text in nested Master Pages from Content on button click
This is the situation. 情况就是这样。 I have a masterpage Site. 我有一个主页网站。
Master that contains another masterpage Shop.Master. 包含另一个主页Shop.Master的主人。
Inside Shop.Master there is a ContentPlaceHolder that loads Something.aspx . 在Shop.Master里面有一个ContentPlaceHolder加载Something.aspx。
Inside the top-masterpage there is a label [lblText]
present. 在top-masterpage内部有一个标签[lblText]
。
The page Something.aspx contains a textbox [boxInput]
and a button [btnButton]
. Something.aspx页面包含一个文本框[boxInput]
和一个按钮[btnButton]
。
What I'm trying to accomplish is when I click button [btnButton]
the value lblText.Text
is being set to the content of [boxInput]
. 我想要完成的是当我点击按钮[btnButton]
,值lblText.Text
被设置为[boxInput]
的内容。
Here is an abstract view of the problem. 这是问题的抽象视图。
I hope you guys can help me out. 我希望你们能帮助我。 Google isn't being a great help this time. Google这次不是一个很好的帮助。
Thanks in advance. 提前致谢。
try like this. 试试这样。 may it helps 可能有帮助
ContentPlaceHolder plchldr= this.Master.Master.FindControl("YourMainMasterContentID") as ContentPlaceHolder;
Label lbl = plchldr.FindControl("lblText") as Label;
if(lbl !=null)
{
lbl.Text="SomeText"
}
This is generally a bit of a weird problem. 这通常是一个奇怪的问题。 The only way I've been able to solve this in the past, is something like: 我过去能够解决这个问题的唯一方法是:
((MasterPageType)this.Master).lblText = "Whatever";
You may need to bubble-up two master pages, as per your specific situation: 根据您的具体情况,您可能需要冒泡两个母版页:
((MasterPageRootType)((MasterPageType)this.Master).Master).lblText = "Whatever";
This will obviously fail if you change your Masterpage to be of a different type. 如果您将主页更改为其他类型,这显然会失败。
(I's been ages since I did WebForms, so forgive me if this isn't 100%) (自从我做了WebForms以来,我已经很久了,所以请原谅我,如果这不是100%)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.