0

I want to change text of label in master page from another page. In master page, code of label which I want to change text is like this:

 <div align="right" style="padding-right: 15px">
    <asp:Label ID="labelIsim" runat="server" Font-Bold="True" Font-Size="Small" 
          ForeColor="White" Font-Italic="True" >labelname</asp:Label>
         <br />
  </div>

I write a code something like this:

  Label m = (Label)Master.FindControl("labelIsim");
  string yname = Session["name"].ToString() + " " + Session["lastname"].ToString();
  m.Text = yname;
  m.Visible = true;

But text of label remained same.Program didn't give any error.It can find the right label, in m.Text; I see the right values but I couldn't see the changes in the browser.where is the mistake ? thanks..

EDIT:

Actually this code changes the text but when I go another page, text of label returns default value. How can I prevent this?

2
  • 1
    In which event of page life cycle, do you write the above code?
    – Anand
    Dec 28, 2011 at 12:11
  • when user presses the login button. In button click event.
    – user741319
    Dec 28, 2011 at 12:15

2 Answers 2

2

You should store it's state in viewstate and then take the values you store in viewstate and set those in the load event of the label.

1

Yes, that's because you have the string labelname in your markup. Unless you re-run your code in every child page it will go back to default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.