Sunday, October 6, 2013

RegisterForEventValidation can only be called during Render();






 
 
When we export gridview data to excel,word,notepad and csv using asp.net  we found this type of error :
 
 
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.
 
 
Second problem in export to excel is  :
 
  "Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
 
 
Add this code in server side :
 
 
public override void VerifyRenderingInServerForm(Control control)
    {
        //It solves the error "Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
    } 

If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website