Html Form inside ASP.Net page causes no postbacks

I needed to re-design an existing asp.net page to include new html, created by third party designer.
After I've done the changes, I found that postbacks are not working.
It took me a while to understand that the cause of the problem is an html form, included in the main ASP.Net form like the following:

  <form method="post" action="about/subscribe/" id="Mail"><input type="text" value="Enter your email address" name="mail" class="field-subscribe"/>

<input type="image" align="middle" class="field-go" src="Images/button_goheader.gif" value="Go"/>

</form>

Note that buttons before html form are sending postbacks correctly, but those that are after the form in the html, are broken.  

So I  removed form, but  posted field to external URL  using PostBackUrl property:

 <asp:ImageButton ImageUrl="~/Images/button_goheader.gif" PostBackUrl="about/subscribe/" runat="server" ToolTip=""Go"" align="middle" class="field-go" />

As an option, html form can be put into separate page and inserted into IFRAME on the main asp.net form.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Thursday, January 17, 2008 6:08 PM
Print

Comments on this entry:

# re: Html Form inside ASP.Net page causes no postbacks

Left by Claudio at 9/18/2008 9:04 AM
Gravatar
You are a GENIOUS. I spent 4 hours before reading this. thanks a lot!

# re: Html Form inside ASP.Net page causes no postbacks

Left by Matt at 11/24/2008 8:44 AM
Gravatar
ME TOO. Thank you sooooo much man.

# re: Html Form inside ASP.Net page causes no postbacks

Left by Amin Rajaee at 8/8/2009 5:41 AM
Gravatar
you can insert a < /form > tang before your html form to close the asp.net form tag. do not forget to add a < form > tang after the html form ends.

# re: Html Form inside ASP.Net page causes no postbacks

Left by Giuliano at 10/14/2009 7:40 AM
Gravatar
Just put a Dummy form inside your aspnetform, cause asp.net overrides the first form tag inside an asp.net form.
Example: if you have 3 forms inside .net form like this:
<form id="dummie"></form>
<form id="frm1" ><input...</form>
<form id="frm2" ><input...</form>
Aspnet Framework will remove JUST the first one(dummie).
*Note: for the first one(the dummy) you don't need to set the id attribute, just open and close the form.

# re: Html Form inside ASP.Net page causes no postbacks

Left by Michael Freidgeim at 10/14/2009 3:44 PM
Gravatar
Giuliano,
I don't understand, why do you need to insert extra forms. To confuse ASP.NET even more?

# re: Html Form inside ASP.Net page causes no postbacks

Left by Simon at 10/28/2009 7:00 AM
Gravatar
Thank you for this post, very useful!

Giuliano simply provided an alternative option

# re: Html Form inside ASP.Net page causes no postbacks

Left by sami at 12/10/2009 11:43 AM
Gravatar
Thanks to both Giuliano and Michael! :)

# re: Html Form inside ASP.Net page causes no postbacks

Left by Mansoor at 6/13/2011 6:06 AM
Gravatar
Giuliano and Michael you are great you have eliminated my biggest trouble :) weldone and keep it up please

# re: Html Form inside ASP.Net page causes no postbacks

Left by Ali at 6/27/2011 9:17 AM
Gravatar
ASP doesn't override the first form. By default ASP pages are just a form. So when you add the closing form tag "</form>" It closes the ASP auto generated form. If you want to add your own form just add the closing form tag at the begining of your page (this closes the asp form), if you also add an open tag this will mean that there is an extra open tag in your markup without it's closing tag. But then at the end of your page ASP will have added in their closing form tag. Just add in an open tag at the end of the page. This way all your mark up will be good. Forms cannot be nested in HTML. So un like you might nest a div inside a div, this doesn't work for form markup.

# re: Html Form inside ASP.Net page causes no postbacks

Left by Alejandro at 11/12/2011 1:05 PM
Gravatar
Hola,
miren aveces no se produce el postback
porque puede que tengamos un form dentro de otro form
ejemplo
<form id="dummie">
<form id="frm1" ></form>
</form>
esto te puede causar problemas

saludos,
desde medellin colombia

# re: Html Form inside ASP.Net page causes no postbacks

Left by Lovel at 12/19/2011 9:09 PM
Gravatar
Thanks This Info was so Important For Us..!

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910