Wednesday, August 31, 2011

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

Introduction:

Here I will explain how to solve the problem
Control 'gvdetails' of type 'GridView' must be placed inside a form tag with runat=server during export of gridview to excel or word or csv using asp.net.

Description:

During export a gridview to excel, word, notepad or csv I got error like

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


This error occurs whenever I am trying to export gridview data to excel or word or csv because compiler thinks that the control is not added to the form.

To solve this problem I have added one overriding function VerifyRenderingInServerForm event in code behind it solves my problem.

public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
By Setting adding this function in code behind that problem has solved and code runs successfully.

I hope it helps to solve your problem.

0 comments:

Post a Comment