嗨,我创建了一个服务器控件,它由 以下所有六个页面组成<UL>
,
我只想在
下面的所有六个页面中重用我的菜单是控件代码 Asp 代码<LI>
<%@ Control Language="C#" ClassName="Menu" %>
<ul id="ulSideBar" class="nav nav-list" runat="server">
<li accesskey="1" id="liDefault" runat="server" **class="active"**>
<asp:LinkButton runat="server" ID="lnkDefault" OnClick="lnkDefault_Click">Introduction</asp:LinkButton></li>
<li accesskey="2" id="liSquad" runat="server">
<asp:LinkButton runat="server" ID="lnkSquad" OnClick="lnkSquad_Click">Squad</asp:LinkButton>
</li>
<li accesskey="3" id="liGallery" runat="server">
<asp:LinkButton runat="server" ID="lnkGallery" OnClick="lnkGallery_Click">Gallery</asp:LinkButton>
</li>
<li accesskey="4" id="liMatches" runat="server">
<asp:LinkButton runat="server" ID="lnkMatches" OnClick="lnkMatches_Click">Matches</asp:LinkButton>
</li>
<li accesskey="5" id="liActivities" runat="server">
<asp:LinkButton runat="server" ID="lnkActivities" OnClick="lnkActivities_Click">Activities</asp:LinkButton>
</li>
<li accesskey="6" id="liNewsFeed" runat="server">
<asp:LinkButton runat="server" ID="lnkNewsFeed" OnClick="lnkNewsFeed_Click">News Feed</asp:LinkButton>
</li>
</ul>
我在我的六个页面中使用此控件现在我的问题是如何更改class=active无论<li>
我点击哪个,只能通过服务器端
我已经在 Control 的代码隐藏中尝试过这段代码,但它不起作用
protected void lnkDefault_Click(object sender, EventArgs e)
{
liDefault.Attributes.Add("class", "active");
liSquad.Attributes.Remove("class");
liGallery.Attributes.Remove("class");
liMatches.Attributes.Remove("class");
liActivities.Attributes.Remove("class");
liNewsFeed.Attributes.Remove("class");
Response.Redirect("Default.aspx");
}
protected void lnkSquad_Click(object sender, EventArgs e)
{
liDefault.Attributes.Remove("class");
liSquad.Attributes.Add("class", "active");
liGallery.Attributes.Remove("class");
liMatches.Attributes.Remove("class");
liActivities.Attributes.Remove("class");
liNewsFeed.Attributes.Remove("class");
Response.Redirect("Squad.aspx");
}
protected void lnkGallery_Click(object sender, EventArgs e)
{
liSquad.Attributes.Remove("class");
liDefault.Attributes.Remove("class");
liGallery.Attributes.Add("class", "active");
liMatches.Attributes.Remove("class");
liActivities.Attributes.Remove("class");
liNewsFeed.Attributes.Remove("class");
Response.Redirect("Gallery.aspx");
}
protected void lnkMatches_Click(object sender, EventArgs e)
{
liDefault.Attributes.Remove("class");
liSquad.Attributes.Remove("class");
liGallery.Attributes.Remove("class");
liMatches.Attributes.Add("class", "active");
liActivities.Attributes.Remove("class");
liNewsFeed.Attributes.Remove("class");
Response.Redirect("Matches.aspx");
}
protected void lnkActivities_Click(object sender, EventArgs e)
{
liDefault.Attributes.Remove("class");
liSquad.Attributes.Remove("class");
liGallery.Attributes.Remove("class");
liMatches.Attributes.Remove("class");
liActivities.Attributes.Add("class", "active");
liNewsFeed.Attributes.Remove("class");
Response.Redirect("Activities.aspx");
}
protected void lnkNewsFeed_Click(object sender, EventArgs e)
{
liDefault.Attributes.Remove("class");
liSquad.Attributes.Add("class", "active");
liGallery.Attributes.Remove("class");
liMatches.Attributes.Remove("class");
liActivities.Attributes.Remove("class");
liNewsFeed.Attributes.Add("class", "active");
Response.Redirect("NewsFeed.aspx");
}