Q:

Calling this.PageRenderControl throws "A page can have one server-side form tag"

I need to generate a pdf with html page contents. I have the following code in Pre_render event:
StringWriter sw = new StringWriter(); 
HtmlTextWriter hw = new HtmlTextWriter(sw);

this.Page.RenderControl(hw); 
string pageContent = sw.ToString();

// Generate PDF file to export
some code..

This throws a "A page can have one server-side form tag" . If I override the Render method to do nothing, the generated pdf has no contents. Any workaround to prevent this?

A:

When you get the HTML of the entire page and render it to the client, you now have two forms with the runat="server" attribute. Do not render the entire page to HTML and write it to the client like that. If you update your question and say what you're trying to accomplish (which you should have provided in the first place) then we can give you alternatives to re-rendering the HTML of the entire page to the client.
If you want to generate a PDF with the information that's contained on the page, I suggest you custom build your PDF rather than rendering the page contents to the PDF as the results are less controllable.
However, if you must do the page contents, then put all your page content inside in a Panel, then render than Panel instead of the Page.
<asp:Panel runat="server" id="PageContents">
<%-- Put your page contents here, inside the Panel --%>
</asp:Panel>

Then in your code...
StringWriter sw = new StringWriter(); 
HtmlTextWriter hw = new HtmlTextWriter(sw);
PageContents.RenderControl(hw); 
string pageContent = sw.ToString();

// Generate PDF file to export
some code..

