Asp.net 在嵌套母版页中更改或添加列表项类
我在li.Attributes.Add(“class”,“current”)上得到一个空异常错误 母版页:Asp.net 在嵌套母版页中更改或添加列表项类,asp.net,vb.net,Asp.net,Vb.net,我在li.Attributes.Add(“class”,“current”)上得到一个空异常错误 母版页: <ul> <li id="li01"><a href="page1.aspx" title="Page 1">Page 1</a</li> <li id="li02"><a href="page2.aspx" title="Page 2">Page 2</a></li> &
<ul>
<li id="li01"><a href="page1.aspx" title="Page 1">Page 1</a</li>
<li id="li02"><a href="page2.aspx" title="Page 2">Page 2</a></li>
<ul>
谢谢。删除me.Page的引用 请尝试以下代码:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim li As System.Web.UI.HtmlControls.HtmlGenericControl = DirectCast(Master.FindControl("li02"), System.Web.UI.HtmlControls.HtmlGenericControl)
li.Attributes.Add("class", "current")
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim li As System.Web.UI.HtmlControls.HtmlGenericControl = DirectCast(Master.FindControl("li02"), System.Web.UI.HtmlControls.HtmlGenericControl)
li.Attributes.Add("class", "current")
End Sub