Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 ASP.NET
Cry | :(( Hi all,
Iam getting this error while transferring data from gridview to excel, can any one suggest me the solution"RegisterForEventValidation can only be called during Render();"
Posted 29-Nov-09 17:26pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this,
 
Set EventValidation to false for the page and also override VerifyRenderingInServerForm in code behind,
public override void VerifyRenderingInServerForm(Control control)
{
 
}
  Permalink  
Comments
Chinwendu at 25-Apr-14 6:53am
   
Setting the page EventValidation to false helped solved my challange.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

hi,
i also faced with the same problem before and finally with the following changes my problem solved.
please check
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Records.aspx.cs" Inherits="Records" 
MasterPageFile="~/Master.master"  EnableEventValidation="false" %>
 
public override void VerifyRenderingInServerForm(Control control)
    {
        /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
           server control at run time. */
    }
  Permalink  
v2
Comments
kiransolkar at 29-Feb-12 6:39am
   
it works thnx
Ramprakashram at 30-Sep-13 0:55am
   
yep..its working now :) tnq
pratheeshsaji at 8-Mar-13 7:46am
   
thanq so much..
manojmadhuranga at 18-Dec-13 2:26am
   
Thanks..It worked for me..just doing this..[ EnableEventValidation="false" ]
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hey just set viewstate false
 
//Turn off the view state
this.EnableViewState = False;
//Remove the charset from the Content-Type header
Response.Charset = String.Empty;
 
and
EnableEventValidation="false"
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" enableEventValidation ="false" Inherits="Default" %>
 

 

also add
 
public override void VerifyRenderingInServerForm(Control control)
{
 
}
  Permalink  
v2
Comments
Jhonnie Walker at 7-Nov-13 7:09am
   
is this a good way to solve this problem..??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Try This in Your .cs page and remember to do EnableEventValidation="false" in your .aspx page.
 
 protected void btnexcel_Click(object sender, EventArgs e)
    {
        string attachment = "attachment; filename=Stock.xls";
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        viewItemList5.AllowPaging = false;
        HtmlForm frm = new HtmlForm();
        //Turn off the view state
        this.EnableViewState = false;
        //Remove the charset from the Content-Type header
        Response.Charset = String.Empty;
        viewItemList5.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(viewItemList5);
        frm.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
 
    }
  Permalink  
Comments
SoMad at 29-Mar-14 2:20am
   
Dude, this question is over 4 years old!
 
Soren Madsen
Silvercorer at 29-Mar-14 5:04am
   
I hadn't found your solution posted above.. 2 years ago..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 28 Mar 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100