简单的asp.net web表单与选定的类UL李菜单 [英] simple asp.net webforms ul li menu with selected class
问题描述
我在它的链接一个简单的无序列表。
I have a simple unordered list with links in it.
<body>
<div id="topMenu">
<ul>
<li><a class="selected" href="../Default.aspx">Start</a></li>
<li><a href="../Category/ShowAll.aspx">Categories</a></li>
<li><a href="../Elements/ShowAll.aspx">Elements</a></li>
<li><a href="../Articles/ShowAll.aspx">Articles</a></li>
</ul>
</div>
<asp:ContentPlaceHolder ID="MainContentPlaceholder" runat="server">
</asp:ContentPlaceHolder>
</body>
我想修改类的链接我点击了选择了类,这是做到这一点的最简单方式。我想过使它成为linkbuttons并保存在会话中的信息,但似乎矫枉过正,必须有一个更简单的方法呢?
I want to change the class of the link i click to the "selected" class, which is the easiest way to do this. I thought about making it into linkbuttons and saving the info in the session, but that seems overkill, there has to be an easier approach?
推荐答案
好了,你可以把&LT; A&GT;
是 RUNAT =服务器
,然后从codebehind访问它们:
Well, you can just put the <a>
to be runat="server"
and then access them from codebehind:
hyperLink.Attributes["class"] = "opened";
您可以与您的菜单母版页有这样的,他们需要选择的,你可以有你的孩子送网页的超级链接的ID,像
You can have this in your master page with the menu, and you can have your child pages send the id of the hyperlink they need selected, something like
在你的主人(该linkWrapper可以成为你的&LT; UL&GT;
为 RUNAT服务器
):
In your master (the linkWrapper can be your <ul>
as runat server
):
(HyperLink)linkWrapper.FindControl(childPageMenuAnchorLinkId);
在你的孩子:
masterPage.ChildPageMenuAnchorLinkId = "link_Customers";
这篇关于简单的asp.net web表单与选定的类UL李菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!