Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to assign the username to the label [placed in Menu] after login in the application e.g. Hello <username>

ASP.NET
<div id="toprightPan2"> 
	<ul>
	<li class="login"><a href="Login.aspx"><asp:Label ID="lblLogin" runat="server" Text="Login"></asp:Label></a></li>
        <li class="reg"><a href="Register.aspx"><asp:Label ID="lblRegister" runat="server" Text="Register"></asp:Label></a></li>
    </ul> 
</div>


-I am using style sheet and placed my ID i.e. toprightpan2
-I have placed this code in Master page
-But i need to change the Text of labels when the user login on a child page. I am unable to do because the content is in master page and remain same in all other pages.

Kindly solve this problem, i will be very thankful to you.
Posted

Its better if you create two properties on master page.... and access those properties on content page..
For eg.
1) On Master Page code create property
Public string LoginText
{
get
{
return lblLogin.Text;
}
Set
{
lblLogin.Text = value;
}
}

2) On the Content Page in aspx File, add a following directive after page directive
<%@ MasterType virtualPath="~/MasterPage.master"%>

3) Now in the code file of Content Page, You can access the property using
Master.LoginText = " Value you want to set ";
 
Share this answer
 
If I understand you correctly... :)

You can use find method like
C#
var lvl = this.Master.FindControl("lblLogin") as Label;
lvl.Text = "something new";


Or a better way to avoid using string is that, you can create a property in Master page & access it from child page like
C#
this.Master.Message = "something new"; // Message is the prop. in master page
 
Share this answer
 
v2
One simple solution to your problem is:
Label lblLogin  =(Label)Page.Master.FindControl("lblLogin");
lblLogin.Text = "New Text";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900