日期:2014-05-19  浏览次数:20494 次

[100分求解]A page can have only one server-side Form tag. 异常
1.页面肯定只有一个form
2.一个页面,一个按钮,按钮里执行下面的代码:
System.IO.StringWriter   tw   =   new   System.IO.StringWriter();
HtmlTextWriter   wt   =   new   HtmlTextWriter(tw);
this.RenderControl(wt);
string   html   =   tw.ToString();

wt.Close();
tw.Close();


//然后报如下异常
A   page   can   have   only   one   server-side   Form   tag.  
Description:   An   unhandled   exception   occurred   during   the   execution   of   the   current   web   request.   Please   review   the   stack   trace   for   more   information   about   the   error   and   where   it   originated   in   the   code.  

Exception   Details:   System.Web.HttpException:   A   page   can   have   only   one   server-side   Form   tag.

Source   Error:  

An   unhandled   exception   was   generated   during   the   execution   of   the   current   web   request.   Information   regarding   the   origin   and   location   of   the   exception   can   be   identified   using   the   exception   stack   trace   below.    

Stack   Trace:  


[HttpException   (0x80004005):   A   page   can   have   only   one   server-side   Form   tag.]
      System.Web.UI.Page.OnFormRender(HtmlTextWriter   writer,   String   formUniqueID)
      System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter   writer)
      System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter   writer)
      System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter   output)
      System.Web.UI.Control.RenderControl(HtmlTextWriter   writer)
      System.Web.UI.Control.RenderChildren(HtmlTextWriter   writer)
      System.Web.UI.Control.Render(HtmlTextWriter   writer)
      System.Web.UI.Control.RenderControl(HtmlTextWriter   writer)
      System.Web.UI.Page.ProcessRequestMain()

 


------解决方案--------------------
System.IO.StringWriter tw = new System.IO.StringWriter(); HtmlTextWriter wt = new HtmlTextWriter(tw); this.RenderControl(wt); string html = tw.ToString(); Response.Write(Server.HtmlEncode(html)); wt.Close(); tw.Close(); Response.End();
------解决方案--------------------
是的,你REender了一个出来

Response.Clear();
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter wt = new HtmlTextWriter(tw);
this.RenderControl(wt);
string html = tw.ToString();

wt.Close();
tw.Close();
Response.End();