2012-07-11 66 views
1

H已经创建了一个带有菜单div的母版页。我将索引页作为登录页面,因此我在index.aspx中使用登录控件,该索引在母版页下注册。如何在主页面登录后获取菜单?

现在我的问题是我怎么能隐藏菜单DIV这是在母版页,直到用户不登录,用户以后做成功登录菜单的div应该出现在用户

回答

1

我把这个代码在我的母版

   <% if (HttpContext.Current.User.Identity.IsAuthenticated) { %> 

        <div>navigation html when is authenticated</div> 

       <% } else { %> 

       <div>navigation html when is NOT authenticated</div> 

       <% } %> 
-1

添加一个@的MasterType指令中内容页面。在该指令中,VirtualPath属性设置为母版页的位置

然后使用Master.FindControl

void Page_Load() 
{ 
// Gets a reference to a TextBox control inside 
// a ContentPlaceHolder 
ContentPlaceHolder mpContentPlaceHolder; 
TextBox mpTextBox; 
mpContentPlaceHolder = 
    (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1"); 
if(mpContentPlaceHolder != null) 
{ 
    mpTextBox = 
     (TextBox) mpContentPlaceHolder.FindControl("TextBox1"); 
    if(mpTextBox != null) 
    { 
     mpTextBox.Text = "TextBox found!"; 
    } 
} 

// Gets a reference to a Label control that not in 
// a ContentPlaceHolder 
Label mpLabel = (Label) Master.FindControl("masterPageLabel"); 
if(mpLabel != null) 
{ 
    Label1.Text = "Master page label = " + mpLabel.Text; 
} 

}

http://msdn.microsoft.com/en-us/library/xxwa0ff0.aspx

+0

这将标记为MVC3,你的回答不适用。 – 2012-07-11 17:42:39

+0

它也被标记为“just”asp.net,所以它适用。也许你应该贴上海报来宣传。 :-P – Joe 2012-07-11 19:40:28

1

在你的主页,你可以做这样的事情:

if (Request.IsAuthenticated) 
{ 
    <p>Welcome back, @User.Identity.Name!</p> 
} 
else 
{ 
    <!-- Put login form here. --> 
} 
相关问题