Question

Asp.net

A.aspx

I'm using JQuery to access an ashx file which loads control ( ascx ) which contains a GridView. The control content is being injected to the page...

When I do this:

   StringWriter writer = new StringWriter();
   HttpContext.Current.Server.Execute(page, writer, false);
   string output = writer.ToString();

It tells me that the GridView must be placed in a form section.

So I've created my Page

public class MyPage: Page
    {
        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }
    }

and inside of it I override this method. I'm using my page and everything is fine.

The question is why ? Why does it have to be in a form? It doesn't have any inputs !

Also, if my ascx contains only <asp:Label ( runatServer) everything is fine and it doesn't require placing it in a Form.

What am I missing ?

Was it helpful?

Solution

It must not be inside of a form, but the only one who knows are you. This exception is also a way to prevent nasty errors and provide a clear error message. Only controls that can postback need to be nested in a HtmlForm control.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top