Saturday, May 03, 2025

Breaking News
>> Securing and encrypt View State and Cookies values  >> Page has one or more controls that do not correspond with   >> “The Controls collection cannot be modified because the control contains code blocks”  >> How to fix "Validation(): Element 'xxxx' is not supported  >> How to create a new session in ASP.NET programmatically  >> MySQL Database Backup using mysqldump command    

Editors Picks

Saturday, March 17, 2012

GridView must be placed inside a form tag with runat=server

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

Here I will explain how to solve the problem Control 'grvtype' of type 'GridView' must be placed inside a form tag with runat=server during if u want to render
Grid view control in HtmlTextWriter
pnlResults.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(sb)));

Control 'grvtype' 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.

No comments :

Post a Comment

Contact Us

Name

Email *

Message *