views:

88

answers:

2

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  A: 

Try sitmap. Implemenation will be very easy.

look at: http://aspnet.4guysfromrolla.com/articles/111605-1.aspx

Saar
I didn't use this route but is a viable option for others
Gary Joynes
+1  A: 

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
Middletone
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
Gary Joynes