Home All Groups Group Topic Archive Search About

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

Author
18 Aug 2006 9:29 PM
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