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

Discussion in 'ASP .Net Web Controls' started by David, Aug 18, 2006.

  1. David

    David Guest

    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
    David, Aug 18, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,055
    Lau Lei Cheong
    May 15, 2004
  2. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    MasterPage -> Page -> MasterPage Code Access

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,870
    Steven Cheng[MSFT]
    Apr 14, 2006
  3. ThunderMusic
    Replies:
    2
    Views:
    434
    Gregory Gadow
    Sep 27, 2006
  4. Torben Laursen
    Replies:
    4
    Views:
    568
    clintonG
    Mar 15, 2008
  5. Jerry Qu
    Replies:
    1
    Views:
    448
    lee atkinson
    Feb 20, 2009
Loading...

Share This Page