Description: In this article I am going to explain how to solve/sort-out the error/problem “Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server” that usually occur while exporting GridView data to MS Excel file or MS Word or PDF or CSV(Comma separated value) file.
Reason and Solution: This exception occurs when one tries to export a GridView control to Word, Excel, PDF, CSV or any other formats. The .net compiler thinks that the control is not added to the form and is rendered, hence it throws this error even if the GridView control is inside the form with runat = “server” tag.
In this case you have to tell the compiler that the control is rendered explicitly by overriding theVerifyRenderingInServerForm event
C#.Net Code
The easiest solution is to add the following overriding function in the code behind file(.aspx.cs) as:
public override void VerifyRenderingInServerForm(Control control)
{
//It solves the error "Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
}
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.