In the Export data to Excel program, there is an error message: The type "GridView" control "GridView1" must be placed in the form tag with Runat=server
Workaround rewrite Verifyrenderinginserverform:
Public Override void Verifyrenderinginserverform (Control control) { //base. Verifyrenderinginserverform (control);}
Verifyrenderinginserverform MSDN:
If the page is not currently in the rendering stage in page processing, and is located in the <form runat=server> tag, the method throws an exception. Controls that need to reside inside the server window can call the method during rendering so that explicit error messages are displayed when they are placed outside. A control that sends back or relies on a registered script block should call the method in an override of the Control.render method. A page that renders a server form element differently can override the method to throw an exception under different conditions. if server controls that echo or use client script are not included in the HtmlForm server control (<form runat="server">), They will not work correctly. These controls can invoke the method at render time to provide explicit error information when they are not included in the HtmlForm control. When you develop a custom server control, you typically call the method when you override the Render method for any type of input tag. This is especially important when the input control calls GetPostBackEventReference or emits client script. The composite server control does not need to make this call. Do not override this method unless you want to create a replacement page frame.
Why do you do this:
Each server-side control of the page executes this method
GridView "Control must be placed inside the form tag with Runat=server" Error Prompt "