一,修改已存在的标签属性
首先我们得在HTML标签中加入runat=“server”属性
<div class="control-group" id="hello" runat="server">
在后台代码中:
hello.Attributes["class"] = "error";
结果
<div class="control-group" id="hello"class="error">
同理可以设置其他的属性
二,动态增加HTML标签
System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
div.ID = "divHeaderContainer";
div.Style.Add("width", this.ScrollWidth.ToString());