Error message: the control "gridview1" of the type "gridview" must be placed in the form tag with runat = server.
When exporting data to an excel program, an error message is displayed: the "gridview1" control type "gridview" must be placed in a form tag with runat = server.
Generally, this is because the <form> label does not contain runat = "server ". But this is in the program! Finally, I checked a lot of information and finally solved the problem.
Reload the verifyrenderinginserverform method in the background file, for example :/? "
Public override void verifyrenderinginserverform (Control)
// Base. verifyrenderinginserverform (control );
PS: verifyrenderinginserverform method description
Page. verifyrenderinginserverform Method
Make sure that the htmlform control is displayed for the specified ASP. NET Server Control at runtime.
[C #] Public Virtual void verifyrenderinginserverform (control); Parameter
ASP. NET Server Control, which must be in the htmlform control.
Exception type condition
The server control specified by httpexception is not included between the start and end mark of the htmlform Server Control at runtime.
If the page is not currently in the rendering phase of page processing and is in the <form runat = Server> flag, this method will cause an exception. Must be in the server form
You can call this method during rendering so that explicit error messages are displayed when they are placed outside. The control that sends back or depends on the registered script block should be in
This method is called in the override of control. Render method. You can rewrite this method for different pages that render server form elements to cause exceptions under different conditions.
If the server controls that return or use client scripts are not included in the htmlform Server Control (<form runat = "server">), they will not work properly
. These controls can call this method during rendering to provide clear error information when they are not included in the htmlform control.
This method is usually called when the render method is rewritten for any type of input tag during custom server control development. This is called in the input control.
It is particularly important when getpostbackeventreference or sending client scripts. This call is not required for composite server controls.
Do not override this method unless you want to create a replacement page framework.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/chenguang79/archive/2010/03/16/5387077.aspx