Patrick.O.Ige

Knowledge Creation is Essential to Business, and Communication is Essential to Knowledge Creation

  Home  |   Contact  |   Syndication    |   Login
  94 Posts | 5 Stories | 342 Comments | 0 Trackbacks

News

SharePoint SharePoint SharePoint

Article Categories

Archives

Post Categories

ADO.NET

Ajax

API/WebServices

ASP.NET Resources

BizTalk Server

Blogs I read

Free Books

How to

JQuery

LINQ

Misc

Mobile BI

Reporting Services

SEO

Sharepoint Resources/Tools

SharePoint 2010 Branding

SharePoint 2010 Videos

SilverLight

SQL Server

Sql Server 2012

SSIS

Windows Phone

WorkFlows

WSS V3

xml

In the days of asp.net 1.1 when using DataGrid and exporting to Excel i never came across this error  since there was no master pages etc..
But at the same time having master pages makes life easier and at the same time some troubles.
One of them is when using Ajax with GridView with a functionality to export to Excel.
The error you get is "Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server" when clicking on your export button.

After nearly pulling my head off i came across some sort of hint that when you have your

GridViewToExport.RenderControl (HtmlTextWriter)  in your code

the page won't know what to do  unless you call this method VerifyRenderingInServerForm method click on the link to
read more . It simply overrides the Render method to ensure that this control is nested in an HtmlForm server control .Anyway after wrapping the method as suggested it worked all well.

But now here comes another trouble when using UpdatePanel in you Gridview and cilck your export button you get error :

inside UpdatePanel control, it gives this error:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from teh server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<div> <table cells'.

And i'm sure you'd say argggg!

But doing EnableEventValidation="false" could solve your problem but in my case i need to use validation on my page.
But i knew some AsyncPostBackTrigger and PostBackTrigger exists after the Triggers even in the UpdatePanel So what i did was do :

<asp:PostBackTrigger ControlID="imgexcel" />

setting the ControlID to the control ID of my asp:imagebutton control

And bingo that did the trick



 


  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Thursday, November 01, 2007 6:56 PM

Feedback

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 6/5/2008 10:21 AM Surekha
Hi,

Perfect Solution! Thanks so much for posting it.

Would it work for attachments also?

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 10/1/2008 4:57 AM David Vasco
Hello
Thanks for the solution, Excellent

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 11/13/2008 12:58 AM Mahadevi
Hello
Thanks so much

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 2/28/2009 8:00 PM Kristaps
Hi! I have the same error:
Control 'GridViewExcel' of type 'GridView' must be placed inside a form tag with runat=server.

But I don't what to do with VerifyRenderingInServerForm method.

Please explain, how can I correct my code!
I'm new in ASP.

Best regards, Kristaps

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 3/1/2009 5:22 PM Patrick
Kristaps send me an email to
naijacoder@hotmail.com
and attach your code

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 3/12/2009 10:26 PM rahul
Hello
Excellent ................

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 3/30/2009 11:35 PM santosh
i am using this in sharepoint
after placing the verify.... also still getting the same

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 5/26/2009 5:29 PM nnet
Control 'ctl00_ContentPlaceHolder1_GVDocument' of type 'GridView' must be placed inside a form tag with runat=server.

error in Line 176: GVDocument.RenderControl(hw)

I don't know what does it mean ?
Thanks.
-nnet-

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 7/2/2009 1:48 PM grif_matt
Thank you so much for posting this article. I was searching for a solution that incorporated Master Pages, Ajax, and a nested Gridview and this was it. As I searched the internet ant I tried something and each time I came across a new error. The render issue, the enable validation issue, and error parsing issue. This was the only article that had a solution for all three in one. The post back trigger was the solution for me.

Thanks

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 9/19/2009 5:50 AM sarang
hello sir,
i callled VerifyRenderingInServerForm method as
protected override void Render(HtmlTextWriter writer)
{
// Ensure that the control is nested in a server form.
if (Page != null)
{
Page.VerifyRenderingInServerForm(this);
}
base.Render(writer);
}
bt prob still exists

so i added

public override void VerifyRenderingInServerForm(Control control)
{

}

method which solved problem

Thank u

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 9/30/2009 9:30 PM Ashby
You're a bloody star! The PostBackTrigger saved the day.

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 11/5/2009 3:35 AM keyur
Nice solution


I solve my prolbem using
one line of code

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 11/12/2009 6:47 AM Tejal
Yeah it is perfect solution.

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 1/15/2010 12:58 PM Shivaraj.gk
Excellent solution... Thank you...

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 4/5/2010 6:45 AM Moolshanker Kothari
Only Add following Event it will work perfect.

public override void VerifyRenderingInServerForm(Control control)
{
return;
}

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 6/11/2010 7:34 AM T.Senthil Kumar.
Hi,

I am getting following error any one can help, please check with attached code.

Error:

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near '<div>

<table cells'.



Code:

protected void btnExportFromGridview_Click(object sender, EventArgs e)
{
ExportGridToExcel(GridView1, "MashreqMysteryRawData");
}

public void ExportGridToExcel(GridView grdGridView, string fileName)
{
//fileName = fileName + "_" + "RawData";

Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", fileName));
Response.Charset = "";

Response.ContentType = "application/vnd.xls";

StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

grdGridView.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.Flush();
Response.End();
}

public override void VerifyRenderingInServerForm(Control control)
{
//return;
}


# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 6/11/2010 8:30 AM Patrick
Have you tried the solution on this post?

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 6/25/2010 1:36 PM basam
It works for me. But I want to export to excel 2007 (not 2003). How can I do that.
thanks

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 7/27/2010 4:24 AM Partha Protim Pal
That a great solution

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 5/26/2011 9:26 AM Ravin Ram
Thanks Moolshanker Kothari for the solution it did the magic.

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server 7/20/2011 3:53 AM Steven M Correia
thanks a lot its worked for me :-)


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: