Home Asp.net Control ‘GridView1’ of type ‘GridView’ must be placed inside a form tag...

Control ‘GridView1’ of type ‘GridView’ must be placed inside a form tag with runat=server

9
5

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

Control GridView1 of type 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#:

//override the VerifyRenderingInServerForm() to verify the control
public override void VerifyRenderingInServerForm(Control control)
{
//Required to verify that the control is rendered properly on page
}

For Vb.net:

//override the VerifyRenderingInServerForm() to verify the control
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
‘Required to verify that the control is rendered properly on page
End Sub

5 COMMENTS

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!