Error when exporting a Gridview to Excel when using Master Pages
If you have a Gridview that exports rows to Excel (see my article Gridview that exports selected rows to Excel for an example) and you are using Master Pages, you are likely to run into the following error:
“Control ‘ctl00_MainContent_Gridview1′ of type ‘GridView’ must be placed inside a form tag with runat=server”, even though you have the supposedly missing form tag.
The reason for this is described in this MSDN page and occurs because ASP.NET does not know to render this control at run time.
Simply adding the following empty function will override the default behaviour:
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control
As Control)
' Nothing needed here...
End Sub
Note that this will only occur if you are using Master Pages.



