1、经过一些挫折后,终于明白了RenderBeginTag和RenderEndTag的用法。
RenderBeginTag和RenderEndTag方法实现了呈现HTML标签的功能,方便灵活。但是它和WriteBeginTag的用法不同。比如:
要呈现<span id="ComboBox19_main" class="WebComboBoxFrame" style="width:184px;"></span>
两者的写法如下:
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_main");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "WebComboBoxFrame");
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, this.Width.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.RenderEndTag();
writer.WriteBeginTag("SPAN");
writer.WriteAttribute("ID", this.ClientID + "_main");
writer.WriteAttribute("CLASS", "WebComboBoxFrame");
writer.WriteAttribute("STYLE", this.Attributes["style"] + ";width:" + this.Width.ToString());
writer.Write(">");
writer.WriteEndTag("SPAN");
注意红色部分是呈现属性和样式的,两者的位置是不同的。
RenderBeginTag和RenderEndTag方法实现了呈现HTML标签的功能,方便灵活。但是它和WriteBeginTag的用法不同。比如:
要呈现<span id="ComboBox19_main" class="WebComboBoxFrame" style="width:184px;"></span>
两者的写法如下:
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_main");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "WebComboBoxFrame");
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, this.Width.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.RenderEndTag();
writer.WriteBeginTag("SPAN");
writer.WriteAttribute("ID", this.ClientID + "_main");
writer.WriteAttribute("CLASS", "WebComboBoxFrame");
writer.WriteAttribute("STYLE", this.Attributes["style"] + ";width:" + this.Width.ToString());
writer.Write(">");
writer.WriteEndTag("SPAN");
注意红色部分是呈现属性和样式的,两者的位置是不同的。