给自定义控件一个模板并输出,可以在重写控件的Render,并使用它的HtmlTextWriter writer 例如:
public class MyTextBox : TextBox { private string _template = " <tr><td> {0} </td><td> {1} </td><td> {3} </td></tr> " ; // 模板 protected override void Render(HtmlTextWriter writer) { TextWriter tempWriter = new StringWriter(); base .Render( new HtmlTextWriter(tempWriter)); StringBuilder sb = new StringBuilder(); sb.AppendFormat( this ._template, " 题目 " , tempWriter.ToString(), " 说明 " ); writer.Write(sb.ToString()); } } 本文转自博客园cloudgamer的博客,原文链接: ,如需转载请自行联系原博主。