Click here to Skip to main content
12,951,732 members (64,218 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I want to assign the username to the label [placed in Menu] after login in the application e.g. Hello <username>

<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 9-Dec-12 6:51am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

One simple solution to your problem is:
 
Label lblLogin  =(Label)Page.Master.FindControl("lblLogin");
lblLogin.Text = "New Text";
 
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

If I understand you correctly... :)

You can use find method like
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
this.Master.Message = "something new"; // Message is the prop. in master page
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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 ";
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100