简体   繁体   中英

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.
Inside Shop.Master there is a ContentPlaceHolder that loads Something.aspx .
Inside the top-masterpage there is a label [lblText] present.
The page Something.aspx contains a textbox [boxInput] and a button [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] .

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.

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%)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM