Josh
Josh

Reputation: 3611

How to nest a form in an ASP.NET page (which has a form wrapped around it)

I am writing HTML to an ASP.NET page (from a web service response), and the HTML has <form> tags. Unfortunately, because the ASP.NET page already has a wrapped around it, a lot of the buttons on the page break. Does anyone know how I can nest the form inside the ASP.NET page without breaking the top-level form?

Note: the HTML I am bringing in is a form with a bunch of hidden fields inside of it, and it has to be placed within the ASP.NET page, and thus nested in the top-level form.

Thanks

Upvotes: 0

Views: 185

Answers (2)

Joel Coehoorn
Joel Coehoorn

Reputation: 415840

ASP.Net webforms does not allow form tags within it's main runat="server" form. You just can't do it. To work around this, you have three options:

  • Have your extra from completely outside of the main runat="server" form, and don't do use any server-side controls or components with that form.
  • Completely switch over to ASP.Net MVC, which likely means a re-write of anything else you've done for this site
  • Parse and adapt the html from the web service to work within your ASP.Net form.

Upvotes: 1

Dan Davies Brackett
Dan Davies Brackett

Reputation: 10071

<form> tags are not allowed to nest inside <form> tags. Depending on the effect you're interested in, you could put the extra <form> outside the ASP.Net one, and use absolute positioning to put it where you want in the page.

Upvotes: 0

Related Questions