Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

value of Master page label not getting updated form content page

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?

like image 252
Muhammad Salman Avatar asked Jun 19 '12 15:06

Muhammad Salman


1 Answers

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");
like image 69
puddleglum Avatar answered Sep 21 '22 08:09

puddleglum