简体   繁体   中英

changing label text in master page from another page

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?

您应该将其状态存储在viewstate中,然后获取存储在viewstate中的值,然后在标签的load事件中进行设置。

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.

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