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

Control 'gvdetails' of type 'GridView' must be placed inside a form tag with runat=server

Mar 30, 2011
Introduction:

Here I will explain how to solve the problem
Control 'gvdetails' of type 'GridView' must be placed inside a form tag with runat=server 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 to excel, word, notepad or csv I got error like 

Control 'gvdetails' of type 'GridView' must be placed inside a form tag with runat=server

This error occurs whenever I am trying to export gridview data to excel or word or csv because compiler thinks that the control is not added to the form.  

To solve this problem I have added one overriding function VerifyRenderingInServerForm event in code behind it solves my problem. 

public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
By Setting adding this function in code behind that problem has solved and code runs successfully.

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

27 comments :

Anonymous said...

222

Anonymous said...

Thank you. It solve my problem.

Fatih KOÇAK said...

that's good, Thank you.

Anonymous said...

Thanks. It solved my Problem.

Anonymous said...

I have used this code but i am getting error like.,


No suitable method found to override

Anonymous said...

I have used this code in a visual webpart 2010 but i am getting error like


No suitable method found to override

William said...

hi man,
I test you code it gives me the following error:
RegisterForEventValidation can only be called during Render();

Line 39: StringWriter sw = new StringWriter();
Line 40: HtmlTextWriter htw = new HtmlTextWriter(sw);
Line 41: gvdetails.RenderControl(htw);
Line 42: Response.Write(sw.ToString());
Line 43: Response.End();

Anonymous said...

it works. very good. thanks in advanced

venky said...

that's thank to code for Gridview data into pdf format Venky Mokka

Unknown said...

Thank. i have a problem if content in gridview is another language

Anonymous said...

i tried code.
but i m getting this error.
(RegisterForEventValidation can only be called during Render();
)
how can i fix it...???

Unknown said...

public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}

This Function are not allow for .ascx Control page.
i am trying it but not successfully implimented.

Unknown said...

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

Unknown said...

how to solve it please help me sir

Mayank said...

I have also added this but got error. As I have put EventValidation = "false" this code works.

Thank you Suresh.
You have saved my lots of time in googling and getting better code.

vivek said...

Can anybody tell me what was problem with code?
Why do we need to call the function-VerifyRenderingInServerForm()

Abhijeet said...

thanks nice explanation

Abhijeet said...

can any budy tell me how to attach and send mail on single click in asp.net c#

Unknown said...

Thank you very much....It solved my issue.

Syed Shoaib Adil said...

What is the solution if we get same probkem within the user coltrol not the page.

I have ascx and my gridview is in it.

Unknown said...

Sir for sorting i find a solution thanks onceagain for your codes

Unknown said...

I get the error when inside a user control.

Unknown said...

thanks

Unknown said...

Hi,

Additional information: RegisterForEventValidation can only be called during Render();

how can i fix this problem...

Unknown said...

how can i Verifies that the control is rendered

Hitesh prajapati said...

registerForEventValidation can only be called during Render();?? help me

Pankaj and Deepak said...

Thanks So much

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 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.