DIV InnerHTML not getting written to HTMLTextWriter if there exists any TextBox control

460 Views Asked by At

I'm writing the below code to get the html of a div element:

var sb = new StringBuilder();
MyDiv.RenderControl(new HtmlTextWriter(new StringWriter(sb)));
string s = sb.ToString();
Session["RecoveryItems"] = s;

But it throws the error:

Textbox controls must be inside a form tag.

I'm using master page with form tag and inside the aspx page i have a user control which contains the div. The div is populated with server code. with table, label control and textbox. I tried adding form tag inside the user control before the div

1

There are 1 best solutions below

0
KarthikBalaraman On

The div element must be inside the form control. Create the div server control in the aspx page and give it an id="someid" and runat="server" attribute and then try adding the textbox to that Div server control