开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜