1

ASP.NET v2

I have MasterPage which includes the navigation bar for the site along the lines of:

<ul>
  <li id="current"><a href="overview.aspx">Home</a></li>
  <li><a href="users.aspx">Users</a></li>
  <li><a href="courses.aspx">Courses</a></li>
</ul>

The css styles the list and id="current" is required to highlight the current page. What is the best way to manipulate the markup so the relevant list item has is assigned id="current" within each page.

2 Answers 2

2

Try sitmap. Implemenation will be very easy.

look at: https://web.archive.org/web/20210510020922/http://aspnet.4guysfromrolla.com/articles/111605-1.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't use this route but is a viable option for others
1

Either use a sitemap or create the control in your code behind in the Page.prerender method.

Your html should look like this:

<ul>
    <li runat="server" id="navul_home">home</li>
    <li runat="server" id="navul_users">users</li>
    <li runat="server" id="navul_courses">courses</li>
</ul>

And the codebehind should be:

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    Dim Currentpage As String = "users"
    navul_home.Attributes.Clear()
    navul_home.Attributes.Clear()
    navul_home.Attributes.Clear()
    Select Case Currentpage
        Case "home"
            navul_home.Attributes.Add("id", "current")
        Case "users"
            navul_users.Attributes.Add("id", "current")
        Case "courses"
            navul_courses.Attributes.Add("id", "current")
    End Select
End Sub

1 Comment

The li elements have an id of navul_home etc. How can these be referenced in the codebehind? In the sample code you have a variable called navul_home but there is no variable with this name, how do you get a reference to the id in the html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.