I have grid view in my user control, and I am getting below error:
RegisterForEventValidation can only be called during Render();
I am using gv.RenderControl(htw);
My code is as below:
private void ExportToExcel(string strFileName, GridView gv)
{
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
And to avoid Server control was created outside form control exception I am using below code:
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
But I'm using all this code in a usercontrol, There isn't this method in the base class. What should I do, even I placed above in my page in which I place my user control, but still I am getting above error
Also note I am using masterpage in which I have form tagged already.