Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

RegisterForEventValidation can only be called during Render();

Apr 2, 2011

Introduction:

Here I will explain how to solve the problem RegisterForEventValidation can only be called during Render(); during export of gridview to excel or word or csv using asp.net.

Description:

In previous post I explained clearly how to show export gridview data to excel,word,notepad and csv using asp.net Export gridview data to Excel,Word . During export a gridview data to excel, word, notepad or csv I got error like 

RegisterForEventValidation can only be called during Render();

This error occurs whenever we are trying to render control to response. To solve this problem I have added EnableEventValidation="false" to @Page directive of aspx page that should be just like this 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportGridviewtoExcel.aspx.cs" Inherits="ExportGridviewtoExcel" EnableEventValidation="false"%>
By Setting EnableEventValidation="false" property to @Page directive of aspx page the problem has solved automatically.

I hope it helps to solve your problem.

Happy Coding………

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

31 comments :

Anonymous said...

Hi, I tried that change as specified here, but I still get the same error. I am using the functionality in a user control and the user control is placed inside the main aspx page where I put this property. Are there any other changs?

Anonymous said...

Wow, so you disable validation and you call that "solving the problem".

Anonymous said...

Worked great once I included the fixes. Thanks for this, solved my current 'crisis'

Anonymous said...

That fixed it, THANKS!!!

i.kamalakannan said...

sir gn, i am happy see your website.Am freshers to asp.net. I need your help. Now am creating master table screen . In that employee screen( branch id* is foreign key ) in aspx file, i want to show branch name * in dropdownlist.But in the gridview branch id only to be stored .Plz help me @ kamalakannan591989@gmail.com

Anonymous said...

Hello, I am Hitesh Gaur.(programmer)

It's a way to solve the problem Mr. Dasari. Before any one tries this I suggest, it will expose your web app/site to some attacks.

Anonymous said...

Yes, It is working.Thanks

Malli Dasari said...

Thanq very much sir,its working great

Anonymous said...

From Microsoft:

Security Note
This feature reduces the risk of unauthorized or malicious postback requests and callbacks. It is strongly recommended that you do not disable event validation.

Anonymous said...

Extender control 'ModalPopupTicket' is not a registered extender control. Extender controls must be registered using RegisterExtenderControl() before calling RegisterScriptDescriptors(). Parameter name: extenderControl

how can i solve this error...plz help me....as eary as possible

katy said...

I don't know how to use CSV!!!

Anonymous said...

Yes dude it's work.... you great....

Vivek Raj said...

is it not true that disabling EnableEventValidation will make your site vulnerable to XSS attacks. i think one should use excel converting libraries.

Anonymous said...

Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.html.simpleparser.TableWrapper'.

outlet said...

I have solve the problem. Thanks a lot!

R.KUBERA SHETTY said...

I sir i am using u r code its working perfectly for grid view but i have some textbox on top of gridview i want export those values to pdf.
I have given like TextBox3.RenderControl(hw);

but its not showing in the pdf document..can u tell me why..and thanks in advance

Anonymous said...

if u still getting error then keep this code in codebehind file and with EnableEventValidation="false"
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
' Verifies that the control is rendered
End Sub

Anonymous said...

I have a doubt Dasari...

your code is perfect but its doesn't work when "sorting" operation performed on grid..

and it doesn't work when grid is empty..

Anupam750 said...

Hello suresh

This is Anupam Singh Jadoun

i am getting error

ould not find a part of the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\Images\16062013969.jpg'

Ashish Shiwakoti said...

Thanks for this once again..

Anonymous said...

I have got dis error " unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type ''iTextSharp.text.Paragraph "

JD Pandey said...

thank u Suresh Ji.....i am filling lucky to joined your group....

Avil Anil said...

nice sir helps me a lot your coding's are awesome

Avil Anil said...

your code is perfect but its doesn't work when "sorting" operation performed on grid..

and it doesn't work when grid is empty..

Anonymous said...

thxx

Anonymous said...

Its awesome page ..each and every query related to ASP.NET will be solved only here...
again thanx sir ji....

gajanan yandarkar said...

we have use your code
But This Give a Error
The remote server returned an error: (500) Internal Server Error.

Chinna Samy said...
This comment has been removed by the author.
murugan said...

thanks its solved

Hadees Shah said...

Its really very helpful..
but i am getting error "unable to evaluate expression because the code is optimized or a native frame"
i am trying to convert string into pdf file and save in a folder but i am not able to do this plz help. thank you

Anonymous said...

thanx dear it solved my problem keep on helping

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.