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


Last night, when i tried to call GridView.RenderControl(), I’s kicked with a runtime exception as below:


What surprised me more, that my GridView is inside the <form> tag, with runat=server attribute. I binged for a while and came to know that I’m not alone for this error. On deep searching, I find that Microsoft Connect has confirmed this as a bug. Which further take me to two other MSDN links:- Link1, Link2.

In the end, I got the fix.

All you’ve to do is to include the below empty-code in the code-behind

// [Code-Behind]
public override void VerifyRenderingInServerForm(Control control)
        //Empty Method