In this article I will explain, how to resolve the error (exception) Control GridView1 of type GridView must be placed inside a form tag with runat=server in ASP.Net.
 
 
Exception
Server Error in '/ASP.Net' Application.
Control 'GridView1' 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 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
 
 
Cause
The above exception occurs when one tries to render a control such as GridView to HTML using the RenderControl method.
But since we are directly rending the control without using a Form, it throws an exception GridView1 of type GridView must be placed inside a form tag with runat=server.
Here the .net compiler thinks that the control is not added to the Form and is being rendered, hence it throws this error even if your GridView control is inside a form with runat = “server”.
 
 
Solution
The solution to the above exception is to override VerifyRenderingInServerForm event handler, thus informing the Compiler that the control has been rendered explicitly.
C#
public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}
 
VB.Net
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
    ' Verifies that the control is rendered
End Sub