为了从服务器端访问这些控件,您需要使它们成为runat ="server"
在代码隐藏中:
foreach(Control ctrl in nav.controls) { if(!ctrl is HtmlAnchor) { string url = ((HtmlAnchor)ctrl).Href; if(url == GetCurrentPage()) // <-- you'd need to write that ctrl.Parent.Attributes.Add("class", "active"); } }