我正在尝试以这种方式自定义 ASP.NET 面板的呈现...
[DefaultProperty("ID")]
[ToolboxData("<{0}:NFormPanel runat=server></{0}:NFormPanel>")]
[Description("Aldammam panel.")]
[ParseChildren(false)]
[PersistChildren(true)]
public class NFormPanel : Panel, INamingContainer
{
protected override void RenderContents(HtmlTextWriter output)
{
var sb = new StringBuilder();
sb.AppendLine("<table class=\"con-table\" style=\"width: 100%;\">");
output.Write(sb.ToString());
if (HasControls())
{
this.RenderChildren(output);
}
sb.Clear();
sb.AppendLine("</table>");
output.Write(sb.ToString());
}
}
...但是输出首先呈现面板控件,然后呈现表格,就像这样......
<div>
<input name="TextBox1" type="text" id="TextBox1">
<table class="con-table" style="width: 100%;">
</table>
</div>
我想要表格内的子控件,如下例所示...
<div>
<table class="con-table" style="width: 100%;">
<input name="TextBox1" type="text" id="TextBox1">
</table>
</div>