finxie
finxie

Reputation: 124

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. enter image description here

I hope you guys can help me out. Google isn't being a great help this time.

Thanks in advance.

Upvotes: 1

Views: 1284

Answers (2)

Ravi Gadag
Ravi Gadag

Reputation: 15861

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"
             }

Upvotes: 2

Dave Bish
Dave Bish

Reputation: 19646

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

Upvotes: 1

Related Questions