给自定义控件一个模板并输出,可以在重写控件的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());
}
}
{
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());
}
}