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 add that DIV to an HtmlForm, so that I can render it to a string. But I get the following error:-
Gridview ‘grv’ must be placed inside a form tag with runat=server, although my Gridview is already inside a form because I added my DIV to the form.
How can I render this DIV to a string ?
Just add the following code in your page
To learn more about it, read the MSDN documentation.