Geeks With Blogs

@azamsharp
  • azamsharp The WWDC app says that there are new videos but there is nothing under videos!!! about 448 days ago
  • azamsharp Can I post my opinion on iOS 7 Beta or is it under NDA or something? about 448 days ago
  • azamsharp iOS 7 BETA installed successfully! about 448 days ago
  • azamsharp iOS 7 BETA installed! Now restoring! I am on NET10 which uses AT&T network. Hopefully 3G will still work! Lets c.. about 448 days ago
  • azamsharp The missing of button borders in Xcode 5 makes it hard to determine the clickable area. about 448 days ago
  • azamsharp I might wait for iOS to be released before I can put it on my device! Don't want a bricked or unstable device! about 448 days ago
  • azamsharp Android has many features that no one uses, number of versions that no one upgrades to and thousands of apps that no one pays for. about 448 days ago
  • azamsharp Maybe it is just me but the new iOS 7 UI looks like Windows Phone 8 UI! #maybeIamCrazy about 448 days ago
  • azamsharp Anyone using H20 network upgraded to iOS 7 BETA Keep me updated if you face any problems. about 448 days ago
  • azamsharp @merowing_ You already downloaded it! I cannot even load the developer's website! :( about 449 days ago

AzamSharp Some day I will know everything. I hope that day never comes.

This error comes when you are exporting the GridView control in the Visual Studio.NET 2005 BETA Versions. I am using the released version so I never got this error. Anyway, you can solve this error but the trick is very dirty. You have to turn the eventValidation off in order for this to work.

You can do this in the web.config file but in this case the eventValidation will be turned off for all the pages.

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

or you can do this in the Page directive which will turn off the validation for a single page.

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

 CodeFile="ExportGridView.aspx.cs" Inherits="ExportGridView" %>

I hope this helps!

powered by IMHO

 

Posted on Wednesday, December 21, 2005 11:39 PM | Back to top


Comments on this post: RegisterForEventValidation can only be called during Render();

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
I´ve got the Released version of Visual Web Developer Express, and im facing this problem, maybe this problem affect beta and express versions?
With this applied to the page it finally works.
Thanks.
Left by David on Jan 13, 2006 6:02 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Setting EnableEventValidation = "false" on the page is your fix? How about you post the implications of that "fix" that you're not mentioning?
Left by Scott on Jan 17, 2006 9:20 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
The bad side of this fix is that Event Validation will be disabled and the page will not check for user's data. This is a big security hole. On the other hand if you are merely displaying the data on the page and there is no user input then its a feasible solution.
Left by AzamSharp on Jan 17, 2006 3:28 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Your explanation doesn't make sense - I am running Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42, which is the released version, not BETA. What difference does the dev tool have?
Left by Edward on Jan 18, 2006 10:30 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
It´s not works!!!!
Left by Jimmy on Mar 22, 2006 8:36 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
I tried your "fix" and it worked for me. It is not a security issue for my app either because there are no user input controls in that page.

Thx.

Ricardo.
http://www.gdltec.com
Left by Ricardo on Mar 28, 2006 9:32 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
I was getting the error when I had paging turned on for the datagrid. I tried this and it took away the error but because I have paging turned on it only exports the page displayed. When I took paging off and took out the EnableEventValidation = "false" I didn't get the error. Is there a way to export all of the data, not just what is displayed on the page?
Left by Charlie on Apr 03, 2006 3:19 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Export to Excel for GridView is working in normal aspx page. But when I implement with ATLAS AJAX Framework, EnableEventValidation = "false" disables all errors and no export is taking place. When I view source in html, I am not able to see GridView control at all.. Any idea how to resolve this???
Left by Siva sakki on Apr 04, 2006 2:36 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Works for me
Thank you
Left by Guille on Apr 28, 2006 12:15 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
How do you do this programmatically. I don't see a Page.EnableEventValidation
Left by Steve on May 02, 2006 10:02 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
You have to use EnableEventValidation = "false" in the page directive.

Hope it helps!
Left by AzamSharp on May 02, 2006 10:02 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
I'm using the Visual Studio 205 Final Release (not the Beta) and I'm getting the error
Left by Colors on May 19, 2006 10:10 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thanks a lot for your information given.

Thanks,
Madhan
Left by Madhan on May 25, 2006 5:36 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
its works fine.

thank you
Left by Vivek on Jun 19, 2006 3:29 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
it was very useful for me

Thanks
Left by Mahendran on Jun 19, 2006 3:34 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Also using release version and this fix worked for me.
Left by Battaile Fauber on Jun 23, 2006 11:04 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thanks Mate, saved me a lot of time.
Left by Sameer on Jun 23, 2006 7:54 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Actually, my company balked at turned off the event validation. It turns out that the error does not occur if you turn sorting off on the grid. Since I need sorting, what I ended up doing was defining a second gridview which looks exactly like the original, but with visible="false". Then when I hit the export button I populate that gridview with the original data, apply the same sort currently used by the displayed grid, make the hidden grid visible and get the result I'm after, but with very messy code >:(

Here is what the export button code looks like now:

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=StackReport.xls");
Response.Charset = String.Empty;
//Response.Cache.SetCacheability(HttpCacheability.NoCache); // Removing this line allows you to "open" without an error instead of just "save as"
Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

ExportGrid.Visible = true;
DataView dv = GetDataView();
dv.Sort = this.SortExpression + " " + this.SortDirection; // i store these in viewstate
ExportGrid.DataSource = dv;
ExportGrid.DataBind();
ExportGrid.RenderControl(htmlWrite);
// DisplayGrid.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();
Left by Battaile Fauber on Jun 26, 2006 11:23 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
I use a command argument in my button that passes the required gridview. I then create an instance of this gridview, remove sorting, paging, and any columns, allow it to autogenerate columns, and then rebind. For example:

Sub ExportButton_Click(sender As Object, e As CommandEventArgs)
Dim TargetGridView As GridView = CType(Page.Controls(0).FindControl("Content").Controls(0).FindControl(e.CommandArgument.ToString()), GridView)

Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=FileName." & Me.Format)
Response.Charset = ""

Response.ContentType = "application/vnd." & Me.Format
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlWrite As System.Web.UI.HtmlTextWriter = new HtmlTextWriter(stringWrite)

TargetGridView.AllowPaging = False
TargetGridView.AllowSorting = False
TargetGridView.AutoGenerateColumns = True

While TargetGridView.Columns.Count > 0
TargetGridView.Columns.Remove(TargetGridView.Columns(0))
End While

TargetGridView.DataBind()
TargetGridView.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
End Sub

Seems to do the job.
Left by Andy on Jul 04, 2006 3:59 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Ignore the Me.Format bits. I created an export button usercontrol, and intended to include export to csv, xml etc. It equates to "xls" for this purpose.
Left by Andy on Jul 04, 2006 4:05 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
I tried turning sorting off. I tried creating a new grid just for export. Neither fix works. I'm using Visual Studio Pro - release version. The only way it works is to use EnableEventValidation="false", which is not a good thing...
Left by Ripley on Jul 05, 2006 2:52 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
My code sort of works.
The part that works is in a multiview that is displayed when the page starts. Single button exports two grids great.

The second grid and button are in a different multiview and that button doesn't seem to work for the export. I get the error everyone else gets atbout RegisterForEventValidation.

is there something special i need to do for multiviews and using multiple buttons to export?
Left by LostInCodeSpace on Jul 06, 2006 1:01 PM

# Sorting and Paging Off
Requesting Gravatar...
You can turn paging and/or sorting off, rebind the grid, export to Excel, then turn paging and/or sorting back on. If you have a multi-page gridview, this will render it to one page for export to Excel and then render it back to where it was. The down side is that it could be a bit slow for large text files.

GridView.AllowPaging = False
GridView.AllowSorting = False
GridView.DataBind()

' Your export routing goes here

GridView.AllowPaging = True
GridView.AllowSorting = True
GridView.DataBind()
Left by Kevin on Sep 11, 2006 1:15 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
I got the RegisterForEventValidation Error as well, I fixed it by adding

GridView.Visible=false;

just before the Response.Clear()

and then added

GridView.Visible=true;

just after the Response.End()

I didn't alter the page tags to turn off event validation, nor did I override VerifyRenderingInServerForm.


Left by Zoggs on Sep 27, 2006 5:29 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
hey Zoggs, your code works well to fixed the message error, but i got no data in my excel a.k.a the export process failed.

Thx,
Left by ajegile on Oct 02, 2006 8:50 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Hi ,

another approach to this problem is not to use the rendercontrol method

Wrap you Gridview in a div
In the Export to Excel method add a javascript that will assign the div's HTML to a hidden Text field

Access this text field from the server and write the Response
Left by Kiran Asokan on Nov 08, 2006 9:18 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thanks for the paging/sorting/export fix Kevin- works perfect!

Left by Colin on Dec 13, 2006 7:37 AM

# during Render();
Requesting Gravatar...
Hey!

the Render() thing sucks but if you can create a page that accepts a SQL query via post or Session you can render that page as an attachment during Render(). It will work seamlessly since it will open a new page that will be an attachment, therefore it won't actually open an extra window just the download box.

Use these functions to fulfill your wildest of excel and gridview relations.

private void ExportGridView()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filenameAlldata.xls");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

}



public override void VerifyRenderingInServerForm(Control control)
{

}
protected override void RenderChildren(HtmlTextWriter output)
{
if (HasControls())
{
// Render Children in reverse order.
for (int i = Controls.Count - 1; i >= 0; --i)
{
Controls[i].RenderControl(output);
}
}
}

protected override void Render(HtmlTextWriter output)
{
// Render Controls.
RenderChildren(output);
sql_set();
}
protected void sql_set()
{
Response.Write(Session["SQL_command"]);
SqlDataSource1.SelectCommand = Session["SQL_command"].ToString();
GridView1.DataBind();
ExportGridView();
}
Left by slacker B on Jan 05, 2007 9:37 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Excellent. The disable sorting and paging worked just fine, but i had to do a second Gridview without Ajax.

Thanks.
Left by Roberto Vargas on Apr 25, 2007 3:03 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Quick fix: EnableEventValidation = "false"

Better solution: Second grid, visible = false with no sorting and no paging for export.

Both worked. Thanks everyone.
Left by McCulloch on Apr 27, 2007 12:22 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
when i try to export the gridview to excel using the same code, and when prompted to open the excel sheet, the sheet does not open and i get an error stating it could not open the document in the tempoary directory. if however i choose to save it first then open it works fine. I am using asp.net 2.0. code is in a user control embedded in an aspx inside a master page.
Left by Cook on May 25, 2007 1:05 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
ITs worked for me . Thanks...
Left by Dharma on Jun 23, 2007 1:57 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
it helps a lot
thank u very much
Left by pankti on Jun 25, 2007 7:14 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
If we do not use Render Control then how to format Excel with items like <DIV> <TABLE> <BR> etc.

When I tried this it is putting everything in the first column including the HTML tags. Any tips on this are greatly appreciated.

Thank You
Left by Ravo on Aug 28, 2007 11:29 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
If I have to use second GridView, I'd like to change it with classics DataGrid instead of GridView which has more easy to RenderControl(htmlWriter),
no need to disallow Sorting, Paging, set visible false, or handling with EnableEventValidation.
Left by Arif Budimartoyo on Sep 27, 2007 3:38 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
It worked for me. I used to do the excel's exporting on asp.net 1.1 and it hadn't this issue but the fix was ok for me.

thanks a lot
Left by Rodrigo on Oct 09, 2007 4:08 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thanks, It works.
Left by Steven on Nov 20, 2007 1:44 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
There is jet another way to solve this. The way I did it is to manualy go though the GridView and extract the data into a table(<table><tr><td>data[row1].cell[cell1].text ect.)
When the data is extracted I !respons.write(data)" to the client

By doning this i dont have to call RenderControl() which is the function causing the trouble..
Left by Tomas on Nov 30, 2007 3:19 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Check this article to solve that easily and securely.

http://boyutal.com/blag/index.php?entry=entry080206-043026



Left by Paul Glenerson on Feb 05, 2008 3:34 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
It Works for me too. Thanks a ton. I dont have any input fields on the form, its just a display of existing data. So Its Ok...
Left by Ramesh on Mar 05, 2008 1:55 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thankx buddy
it's working
Left by swapnal on Apr 07, 2008 2:33 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thanks a lot it's works


Left by Pawan on Apr 14, 2008 10:48 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thanks a lot......it worked.......
Left by Aniketh on Apr 22, 2008 4:40 AM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
It works thanks
Left by sowmya on May 05, 2008 9:09 PM

# re: RegisterForEventValidation can only be called during Render() for usercontrol
Requesting Gravatar...
Hello
i am using updatepanel and on calender click i m loading one usercontrola and in that control creating dynamic table and some controls on that.
when i user rendercontrol method i get the same error.
please help
thanks in advance
Left by Krishna Dave on May 12, 2008 9:44 PM

# re: RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thanks a lot!! I did hours of research to find it! This post really helped me! Thanks God!
Left by Yolanda on Oct 09, 2010 2:33 PM

Your comment:
 (will show your gravatar)
 


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net | Join free