Click here to Skip to main content
15,896,437 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to access master page variable or label, from a content page.

I want when user logged in, his name and logout button appears on the MasterPage.
Posted
Updated 7-May-12 1:02am

Hi ,
Check this
C#
protected void Page_Load(object sender, EventArgs e)
{
   Label lbl = (Label)Master.FindControl("ContentPlaceHolder1").FindControl("Label1");
   string test = lbl.Text;
}


XML
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Label ID="Label1" runat="server" Text="yyyyyyyy"></asp:Label>
</asp:Content>


For Access variable : you can make proprieties .
Best Regards
M.Mitwalli
 
Share this answer
 
This is the sample code in site.master:
ASP.NET
<div class="loginDisplay">
    <asp:LoginView ID="LoginView1" runat="server" EnableViewState="false">
        <AnonymousTemplate>
            [ <a href="~/Account/Login.aspx" id="HeadLoginStatus"
               runat="server">Log In</a> ]
        </AnonymousTemplate>
        <LoggedInTemplate>
            Welcome <span class="bold">
                <asp:LoginName ID="HeadLoginName" runat="server" />
            </span>!
            [ <asp:LoginStatus ID="HeadLoginStatus" runat="server"
                 LogoutAction="Redirect" LogoutText="Log Out"
                LogoutPageUrl="~/" /> ]
        </LoggedInTemplate>
    </asp:LoginView>
</div>

Hope it help
 
Share this answer
 
v2
the problem you are mentioning can normally be handled through sessions
if some certain value is present in session show Logout else show Login.

you need not to interact with master child controls than.

and also the solution provided by Nikfazan is also good. you can try.


Nazish
 
Share this answer
 
In your code behind of the content page access the master page contol using

Master.HeadLoginName.Text = "name"
 
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