Panel控件的RenderControl方法问题,百思不得其解,高手们救命啊
下面的代码用于实现读取Panel3控件的HTML内容,出现一个问题是Panel控件中如果放置可用于用户输入服务器控件例如文本框 RenderControl 方法调用就出现问题了,恳求高手们帮忙解决,用其他方法能实现的也可以,分不够再加,谢谢了
=================== 问题描述如下 ========================================
类型“TextBox”的控件“TextBox1”必须放在具有 runat=server 的窗体标记内。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.Web.HttpException: 类型“TextBox”的控件“TextBox1”必须放在具有 runat=server 的窗体标记内。
源错误:
行 6: System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter( sw );
行 7:
行 8: this.Panel3.RenderControl(htw);//这行代码出现问题
行 9: this.Response.Write( "a: "+sw.ToString());
行 10:
源文件: D:\web\ThinkseaWebsite\a\b.aspx 行: 8
堆栈跟踪:
[HttpException (0x80004005): 类型“TextBox”的控件“TextBox1”必须放在具有 runat=server 的窗体标记内。]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +152
System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter writer) +40
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +17
System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +7
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
ASP.b_aspx.Button1_Click(Object sender, EventArgs e) in D:\web\ThinkseaWebsite\a\b.aspx:8
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
=================== 源码如下 ============================================
<%@ Page language= "c# " %>
<script runat=server>
private void Button1_Click(object sender, System.EventArgs e)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter( sw );
this.Panel3.RenderControl(htw);//这行代码出现问题
this.Response.Write( "a: "+sw.ToString());
htw.Close();
sw.Close();
}
</script>
<HTML>
<body>
<form id= "Form1 " method= "post " runat= "server ">
<asp:Panel id= "Panel3 " runat= "server "> Panel