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.

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

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345