無論是在Page.prerender方法使用Sitemap或在代碼中創建控件後面。
你的HTML應該是這樣的:
<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>
而且代碼隱藏應該是:
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
鋰元素有一個navul_home的id等。如何在代碼隱藏中引用它們?在示例代碼中,您有一個名爲navul_home的變量,但沒有此名稱的變量,您如何獲得對html中id的引用 – 2009-11-06 13:10:38