GridView should be added to the form tag for rendering

TextWriter tr = new StringWriter(); HtmlTextWriter writer = new HtmlTextWriter(tr); HtmlForm form = new HtmlForm(); form.Controls.Add(divQueryDescription); divQueryDescription.RenderControl(writer); <div runat="server" id="divQueryDescription"> <asp:GridView runat="server" id="grv"></asp:GridView> </div> 

My GridView is inside a DIV, and I am adding a DIV to the HtmlForm so that I can display it in a row. But I get the following error: -

The gridview 'grv' needs to be placed inside the form tag using runat = server, although my gridview is already inside the form because I added the DIV to the form.

How can I convert this div to string?

+2
Jun 14 '11 at 10:52
source share
3 answers

Just add the following code on your page

 public override void VerifyRenderingInServerForm(Control control) { return; } 

To learn more about this, read the MSDN documentation .

+4
Jun 14 '11 at 11:18
source share

From what you are showing here, the GridView is not yet in the form element with runat="server" , you need to do something like this:

 <form runat="server"> <div runat="server" id="divQueryDescription"> <asp:GridView runat="server" id="grv"></asp:GridView> </div> </form> 

Of particular note is the <form runat="server"> and its end tag.

Update:

It looks like form is causing problems because it was not written out, you are writing directly from the div : try using form.RenderControl(writer); .

0
Jun 14 2018-11-11T00:
source share

Make sure you have runat = "server" in the form element / element

0
Jun 14 2018-11-11T00:
source share



All Articles