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.
 
RegisterForEventValidation can only be called during Render()
Author Name: Mudassar Khan Published Date: June 18, 2009
Filed Under :
Issues and Exceptions
Views: 5848




Server Error in 'ASP.Net' Application.


RegisterForEventValidation can only be called during Render();

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.InvalidOperationException: RegisterForEventValidation can only be called during Render();

 

 

Cause

The above error occurs when you try to render a control to Response. Generally I got this when I exported GridView to Excel, Word, PDF or CSV formats. The ASP.Net compiler issues the above Exception since it feels the Event is invalid.

 

Solution

The solution is quite simple you need to notify ASP.Net that not to validate the event by setting the EnableEventValidation flag to FALSE.

You can set it in the Web.Config in the following way

<pages enableEventValidation ="false"></pages>

 

This will apply to all the pages in your website. Else you can also set it in the @Page Directive of the page on which you are experiencing the above error.

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation = "false"

 

The above solution helped me resolve my issue. If anyone has something else that helped him please share.

 


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

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