I have a content page I am updating the value of asp:Label of Master page from content page . value do get updated but the updated value is not visible. I tried two method using
1). defining a property (on master page) to set and get label value. e.g.
public string setErrorMsg
{
get { return lbl1.Text; }
set { lbl1.Text = value; }
}
2) by finding control (label of master page) from content page and setting its text. e.g.
Label lblMasterError = this.Page.Master.FindControl("lbl1") as Label;
lblMasterError.Text="text is updated form content page";
both are updating value if I see it in debug mode but updated label value is not visible on content page.What might be the possible reasons for this behavior?
I don't know why is not finding your label but I've had the same to happen before. this is what works for me:
In the master page cs:
public void SetErrorMsg(string ErrorMsg)
{
this.lbl1.Text = ErrorMsg;
}
From aspx page code behind (replace myMasterPage name w/ yours):
((myMasterPage)Master).SetErrorMsg("Some error text");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With