Now here in this tutorial, I’ll explain how to solve the Control ‘GridView1’ of type ‘GridView’ must be placed inside a form tag with runat=server error while exporting gridview data in asp.net.
In my previous tutorials, I’d explained export all gridview data to word excel text or pdf file in asp.net, export only selected rows from gridview to word excel text or pdf file in asp.net, print gridview data on print button click, and other more cracking tutorials on GridView, Asp.net here.
Control GridView1 of type Gridview
Error: ‘GridView’ must be placed inside a form tag with runat=server
Server Error in ‘/’ Application.
Control ‘grdResultDetails’ of type ‘GridView’ must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Control ‘grdResultDetails’ of type ‘GridView’
must be placed inside a form tag with runat=server.
You might get this error while rendering gridview control using RenderControl() method during gridview data export to word, excel, pdf, etc.
Error Cause:
The reason behind this error is that the .NET Compiler doesn’t find the GridView control to the form even if control is exist under the from tag and throws an exception during rendering that control.
Error Solution:
We need to render GridView control explicitly by overriding the VerifyRenderingInServerForm event. To resolve this error, add the following code to your code-behind file.
For C#:
public override void VerifyRenderingInServerForm(Control control)
{
//Required to verify that the control is rendered properly on page
}
For Vb.net:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
‘Required to verify that the control is rendered properly on page
End Sub
Hi, wanted to tell you that you are the best friend , please any help or lend you want to teach I accept , I’m your fan … thank you very much , I used a lot of what you teach in my work.
Glad to hear from you. A lot more to come, stay tuned and happy coding!
hi, it also solved my problem thanks….
Now i am getting only in my excel file
Thank you so much. much need information you have given thank you.