Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET HTML login
I want to assign the username to the label [placed in Menu] after login in the application e.g. Hello
 
<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... Smile | :)
 
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
0 OriginalGriff 410
1 CHill60 255
2 Sergey Alexandrovich Kryukov 170
3 RyanDev 135
4 Richard MacCutchan 115


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