GridView "Control must be placed inside the form tag with Runat=server" Error Prompt "

Source: Internet
Author: User

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 "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.