Using Control.Render() from a page with a MasterPage

D

David

I am trying to use the following code on a page with a master page.

System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw);

// this throws the exception
gridResults.RenderControl(htw);

I am using a ContentPlaceHolder and the form is on the MasterPage.

I get the following error message...
System.Web.HttpException was unhandled by user code
Message="Control 'ctl00_ContentPlaceHolder1_gridResults' of type
'GridView' must be placed inside a form tag with runat=server."
Source="System.Web"
ErrorCode=-2147467259
StackTrace:
at System.Web.UI.Page.VerifyRenderingInServerForm(Control control)
at System.Web.UI.WebControls.GridView.Render(HtmlTextWriter writer,
Boolean renderPanel)
at System.Web.UI.WebControls.GridView.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at ExportData.ExportToExcel() in
c:\Work\SAGEAnalyzerGUI_2\App_Code\ExportData.cs:line 115
at ExportData.Export() in
c:\Work\SAGEAnalyzerGUI_2\App_Code\ExportData.cs:line 100
at PageMaster.ExportToExcel() in
c:\Work\SAGEAnalyzerGUI_2\PageMaster.master.cs:line 32
at FuelBurnResults.BtnExportExcelClick(Object sender, EventArgs e) in
.....

Is there a way to call the Render() method and still use a MasterPage?

Thanks.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top