iterate through NavigateUrls on Page_PreRender and change style
I'm not sure if this is at all possible (there may be a different way to acheive it) but is there a way to iterate though all hyperlinks on Page_PreRender and if the NavigateUrl matches the file name then I can add a class to the link to show this as the active page.
Or even better, iterate through all hyperlink NavigateUrls within a certain DIV.
I can do it individually but that would take too long as there are so many links and be too hard to manage:
Protected Sub Page_PreR开发者_如何学Pythonender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim filePath As String = System.Web.HttpContext.Current.Request.Path
If filePath = "/" & hMembership.NavigateUrl Then
hMembership.CssClass = "active"
End If
End Sub
You can do something like this in the Page_PreRender:
Dim filePath As String = System.Web.HttpContext.Current.Request.Path
For Each Control As Control In Me.Form.Controls
If TypeOf (Control) Is HyperLink Then
With TryCast(Control, HyperLink)
If .NavigateUrl = filePath Then
.CssClass = "active"
End If
End With
End If
Next Control
精彩评论