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. Advertisements

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. Replies:
    0
    Views:
    882
  2. Lau Lei Cheong

    Page.Render do not render complete page

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

    MasterPage -> Page -> MasterPage Code Access

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    8,150
    Steven Cheng[MSFT]
    Apr 14, 2006
  4. ThunderMusic
    Replies:
    2
    Views:
    653
    Gregory Gadow
    Sep 27, 2006
  5. Randy Smith
    Replies:
    9
    Views:
    652
    Mark Rae
    Apr 14, 2007
  6. Torben Laursen
    Replies:
    4
    Views:
    831
    clintonG
    Mar 15, 2008
  7. Jerry Qu
    Replies:
    1
    Views:
    694
    lee atkinson
    Feb 20, 2009
  8. Replies:
    1
    Views:
    605
    Teemu Keiski
    Jul 2, 2003
Loading...