Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server

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



 


posted @ Thursday, November 01, 2007 6:56 PM

Print

Comments on this entry:

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server

Left by Surekha at 6/5/2008 10:21 AM
Gravatar
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

Left by David Vasco at 10/1/2008 4:57 AM
Gravatar
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

Left by Mahadevi at 11/13/2008 12:58 AM
Gravatar
Hello
Thanks so much

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server

Left by Kristaps at 2/28/2009 8:00 PM
Gravatar
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

Left by Patrick at 3/1/2009 5:22 PM
Gravatar
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

Left by rahul at 3/12/2009 10:26 PM
Gravatar
Hello
Excellent ................

# re: Error Control 'ctl00_ContentPlaceHolder1_gdViewExport' of type 'GridView' must be placed inside a form tag with runat=server

Left by santosh at 3/30/2009 11:35 PM
Gravatar
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

Left by nnet at 5/26/2009 5:29 PM
Gravatar
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

Left by grif_matt at 7/2/2009 1:48 PM
Gravatar
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

Left by sarang at 9/19/2009 5:50 AM
Gravatar
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

Left by Ashby at 9/30/2009 9:30 PM
Gravatar
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

Left by keyur at 11/5/2009 3:35 AM
Gravatar
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

Left by Tejal at 11/12/2009 6:47 AM
Gravatar
Yeah it is perfect solution.

Your comment:



 (will not be displayed)


 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345