母版页控制访问 [英] masterpage control access

查看:67
本文介绍了母版页控制访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从内容页面访问母版页变量或标签.

我想要用户登录时,其名称和注销按钮出现在MasterPage上.

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.

推荐答案


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





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



对于Access变量:您可以设置专有属性.
最好的问候
M.Mitwalli



For Access variable : you can make proprieties .
Best Regards
M.Mitwalli


这是site.master中的示例代码:
This is the sample code in site.master:
<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


请参阅这些文章

http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx [ ^ ]

http://www.dotnetfunda. com/articles/article1507-how-to-access-master-page-variableproperty-from-the-content-page.aspx [母版页和内容页的交互 [
Refer these articles

http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx[^]

http://www.dotnetfunda.com/articles/article1507-how-to-access-master-page-variableproperty-from-the-content-page.aspx[^]

Master Page and Content Page Interaction[^]


这篇关于母版页控制访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆