Click here to Skip to main content
11,645,087 members (63,535 online)
Rate this: bad
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"> 
	<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>

-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
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";
Rate this: bad
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
Rate this: bad
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
return lblLogin.Text;
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 ";

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

  Print Answers RSS
0 OriginalGriff 700
1 494
2 Sergey Alexandrovich Kryukov 449
3 Afzaal Ahmad Zeeshan 444
4 CPallini 386
0 OriginalGriff 1,065
1 Sergey Alexandrovich Kryukov 683
2 DamithSL 681
3 Afzaal Ahmad Zeeshan 662
4 CPallini 555

Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2015
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