在每个链接按钮单击时,都会处理事件我们如何在链接按钮单击时更改 cssClass?请注意,每次单击按钮时页面都会刷新。
目前,当我单击任何 LinkButton 时,默认情况下它将 cssClass 设置为 Plus LinkButton
---index.aspx-----------
<ul class="mainMenu">
<li>
<asp:LinkButton ID="lnkHome" runat="server"><span>Home</span></asp:LinkButton>
</li>
<li>
<asp:LinkButton ID="lnkIndia" runat="server"><span>India</span></asp:LinkButton></li>
<li>
<asp:LinkButton ID="lnkWorld" runat="server"><span>World</span></asp:LinkButton></li>
<li>
<asp:LinkButton ID="lnkStates" runat="server"><span>States</span></asp:LinkButton></li>
<li>
<asp:LinkButton ID="lnkCity" runat="server"><span>City</span></asp:LinkButton></li>
<li>
<asp:LinkButton ID="lnkBusiness" runat="server"><span>Business</span></asp:LinkButton></li>
<li>
<asp:LinkButton ID="lnkSport" runat="server"><span>Sport</span></asp:LinkButton></li>
<li>
<asp:LinkButton ID="lnkMagazine" runat="server"><span>Magazine</span></asp:LinkButton></li>
<li>
<asp:LinkButton ID="lnkBlogs" runat="server"><span>Patrika Blogs</span></asp:LinkButton></li>
<li>
<asp:LinkButton ID="lnkPlus" CssClass="active" runat="server"><span>Plus</span></asp:LinkButton></li>
CSS 类
ul.mainMenu{float:right; background:url(../images/menubg.gif) 0 0 repeat-x; width:100%}
ul.mainMenu li{float:left; color:#a7b5be; font-weight:bold; background:url(../images/seprator.gif) right 0 no-repeat; position:relative; z-index:999}
ul.mainMenu li a{color:#586066;line-height:24px;display:inline-block;}
ul.mainMenu li a span{color:#576067; padding:0 11px; line-height:24px; display:inline-block; }
ul.mainMenu li a:hover{background:url(../images/hover.gif) 0 0 repeat-x}
ul.mainMenu li a:hover span{color:#fff}
ul.mainMenu li a.active{background:url(../images/hover.gif) 0 -24px repeat-x;}
ul.mainMenu li a.active span{background:url(../images/redArrow.gif) center bottom no-repeat; padding-bottom:7px; color:#fff}
VB代码
Protected Sub lnkHome_Click(sender As Object, e As EventArgs) Handles lnkHome.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("HomePage")
Else
Response.Redirect("index.aspx")
End If
End Sub
Protected Sub lnkAboutUs_Click(sender As Object, e As EventArgs) Handles lnkAboutUs.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("AboutUsRoute")
Else
Response.Redirect("AboutUs.aspx")
End If
End Sub
Protected Sub lnkContactUs_Click(sender As Object, e As EventArgs) Handles lnkContactUs.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("ContactUsRoute")
Else
Response.Redirect("ContactUs.aspx")
End If
End Sub
Protected Sub lnkFeedback_Click(sender As Object, e As EventArgs) Handles lnkFeedback.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("FeedbackRoute")
Else
Response.Redirect("Feedback.aspx")
End If
End Sub
Protected Sub lnkSiteMap_Click(sender As Object, e As EventArgs) Handles lnkSiteMap.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("SiteMapRoute")
Else
Response.Redirect("Sitemap.aspx")
End If
End Sub
Protected Sub lnkAdvWithUs_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkAdvWithUs.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("AdvertiseWithUsRoute")
Else
Response.Redirect("AdvertiseWithUs.aspx")
End If
End Sub
Protected Sub lnkPrivacyFooter_Click(sender As Object, e As EventArgs) Handles lnkPrivacyFooter.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("PrivacyRoute")
Else
Response.Redirect("PrivacyPolicy.aspx")
End If
End Sub
Protected Sub lnkDisclaimerFooter_Click(sender As Object, e As EventArgs) Handles lnkDisclaimerFooter.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("DisclaimerRoute")
Else
Response.Redirect("Disclaimer.aspx")
End If
End Sub
Protected Sub lnkNewsLetterFooter_Click(sender As Object, e As EventArgs) Handles lnkNewsLetterFooter.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("NewsLetterRoute")
Else
Response.Redirect("NewsLetters.aspx")
End If
End Sub
Protected Sub lnkWorkWithUs_Click(sender As Object, e As EventArgs) Handles lnkWorkWithUs.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("WorkWithUsRoute")
Else
Response.Redirect("WorkWithUs.aspx")
End If
End Sub
Protected Sub lnkIndia_Click(sender As Object, e As EventArgs) Handles lnkIndia.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("CategoryRoute", New With {
.CatName = "India"
})
Else
Response.Redirect("Category.aspx?CatName=India")
End If
End Sub
Protected Sub lnkWorld_Click(sender As Object, e As EventArgs) Handles lnkWorld.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("CategoryRoute", New With {
.CatName = "World"
})
Else
Response.Redirect("Category.aspx?CatName=World")
End If
End Sub
Protected Sub lnkStates_Click(sender As Object, e As EventArgs) Handles lnkStates.Click
End Sub
Protected Sub lnkBusiness_Click(sender As Object, e As EventArgs) Handles lnkBusiness.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("CategoryRoute", New With {
.CatName = "Business"
})
Else
Response.Redirect("Category.aspx?CatName=Business")
End If
End Sub
Protected Sub lnkSport_Click(sender As Object, e As EventArgs) Handles lnkSport.Click
If (ConfigurationManager.AppSettings("SeoFriendlyUrl") = "true") Then
Response.RedirectToRoute("CategoryRoute", New With {
.CatName = "Sports"
})
Else
Response.Redirect("Category.aspx?CatName=Sports")
End If
End Sub