如何在asp.net中隐藏单个特定的HTML标记? [英] How do I hide a single especific HTML tag in asp.net?
本文介绍了如何在asp.net中隐藏单个特定的HTML标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计我有这个代码:
< div class =float-right>
< section id =login>
< asp:LoginView runat =serverViewStateMode =Disabled>
< AnonymousTemplate>
< ul>
< li>< a id =loginLinkrunat =serverhref =〜/ Account / Login>登录< / a>< / li>
< / ul>
< / AnonymousTemplate>
< LoggedInTemplate>
< p>
你好,
< asp:LoginName runat =serverCssClass =UserName/>
!
< asp:LoginStatus runat =serverLogoutAction =RedirectLogoutText =Log offLogoutPageUrl =〜/ Account / Login.aspx/>
< / p>
< / LoggedInTemplate>
< / asp:LoginView>
< / section>
< nav>
< ul id =menu>
< li>< a runat =serverhref =〜/>主页< / a>< / li>
< li>< a runat =serverhref =TF_new.aspx> Schedule Trip< / a>< / li>
< li>< a runat =serverhref =〜/ About>帮助< / a>< / li>
< / ul>
< / nav>
< / div>
< / div>
< / header>
< div id =body>
< asp:ContentPlaceHolder runat =serverID =FeaturedContent/>
< section class =content-wrapper main-content clear-fix>
< asp:ContentPlaceHolder runat =serverID =MainContent/>
< / section>
< / div>
我想隐藏未登录用户的主页...我该怎么做?
我知道如果我把它放在匿名模板中它会被隐藏但是我想这样做而不移动它因为我想这样做其他几件事
解决方案
更改您的主页链接如下
< li id = homeItem runat = server > < a runat = server href = 〜/ > 主页< / a > < / li >
页面加载方法如下所示
homeItem.Visible = HttpContext.Current.User.Identity.IsAuthenticated;
Guys I have this code:
<div class="float-right"> <section id="login"> <asp:LoginView runat="server" ViewStateMode="Disabled"> <AnonymousTemplate> <ul> <li><a id="loginLink" runat="server" href="~/Account/Login">Log in</a></li> </ul> </AnonymousTemplate> <LoggedInTemplate> <p> Hello, <asp:LoginName runat="server" CssClass="UserName" /> ! <asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/Account/Login.aspx" /> </p> </LoggedInTemplate> </asp:LoginView> </section> <nav> <ul id="menu"> <li><a runat="server" href="~/">Home</a></li> <li><a runat="server" href="TF_new.aspx">Schedule Trip</a></li> <li><a runat="server" href="~/About">Help</a></li> </ul> </nav> </div> </div> </header> <div id="body"> <asp:ContentPlaceHolder runat="server" ID="FeaturedContent" /> <section class="content-wrapper main-content clear-fix"> <asp:ContentPlaceHolder runat="server" ID="MainContent" /> </section> </div>
And i want to hide the Home page from users that are not logged in... how do I do it?
I know that if I put it inside the Anonymous Template it will be hidden but I wanted to do it without moving it since I want to do this to several others things
解决方案
change your home link as below
<li id="homeItem" runat="server" ><a runat="server" href="~/">Home</a></li>
in page load method do as below
homeItem.Visible = HttpContext.Current.User.Identity.IsAuthenticated;
这篇关于如何在asp.net中隐藏单个特定的HTML标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文