ASPSnippets

Alerts
Get notified when a new article is published.

Name
 
Email

Your email will always be private and will not be shared.

Follow us on twitter.
 
Exception - Control GridView1 of type GridView must be placed inside a form tag with runatserver.
Author Name: Mudassar Khan Published Date: May 24, 2009
Filed Under :
Issues and Exceptions
Views: 4899

Server Error in '/ASP.Net' Application.


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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

 

Cause

The above exception occurs when one tries to export a GridView control to Word, Excel, PDF, CSV or any other formats. Here the .net compiler thinks that the control is not added to the form and is rendered, hence it throws this error even if your GridView control is inside a form with runat = “server”.

 

Solution

1. Tell the compiler that the control is rendered explicitly by overriding the VerifyRenderingInServerForm event. You can do that by adding the event to tha code behind file. Refer below

 

C#

public override void VerifyRenderingInServerForm(Control control)

{

    /* Verifies that the control is rendered */

}

 

VB.Net

Public Overloads Overrides Sub VerifyRenderingInServerForm ByVal control As Control)

        ' Verifies that the control is rendered

End Sub

 

If anyone has some other solution please share. If you have any other exception do submit it to us using the Contact page.


If you like this article, help us grow by bookmarking this page on any social bookmarking site.
Bookmark and Share Page copy protected against web site content infringement by Copyscape

Related Articles

Comments

Dinesh said:
while exporting file it shows msg threads was being aborted br and then shows File Download Dialogbr how can we avoid msgbox
March 09, 2010  

Mudassar Khan said:
Reply To: Dinesh
That's because of Response.End
Simply ignore that exception
March 10, 2010  

Add Comments

You can add your comment about this article using the form below. Make sure you provide a valid email address
else you won't be notified when the author replies to your comment

Please note that all comments are moderated and will be deleted if they are
  • Not relavant to the article
  • Spam
  • Advertising campaigns or links to other sites
  • Abusive content.
There is no need to add BR tags. Simply press enter for new line

Name*  
Email*
Comment*  
Security code
Security code