Reputation: 625
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?
Upvotes: 0
Views: 3116
Reputation: 699
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.
Upvotes: 2
Reputation: 579
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.
Upvotes: 1