Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

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 on Thursday, January 17, 2008 6:08 PM ASP.NET , CSS/DHTML/JavaScript | Back to top


Comments on this post: Html Form inside ASP.Net page causes no postbacks

# re: Html Form inside ASP.Net page causes no postbacks
Requesting Gravatar...
You are a GENIOUS. I spent 4 hours before reading this. thanks a lot!
Left by Claudio on Sep 18, 2008 9:04 AM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting Gravatar...
ME TOO. Thank you sooooo much man.
Left by Matt on Nov 24, 2008 8:44 AM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting 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.
Left by Amin Rajaee on Aug 08, 2009 5:41 AM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting 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.
Left by Giuliano on Oct 14, 2009 7:40 AM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting Gravatar...
Giuliano,
I don't understand, why do you need to insert extra forms. To confuse ASP.NET even more?
Left by Michael Freidgeim on Oct 14, 2009 3:44 PM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting Gravatar...
Thank you for this post, very useful!

Giuliano simply provided an alternative option
Left by Simon on Oct 28, 2009 7:00 AM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting Gravatar...
Thanks to both Giuliano and Michael! :)
Left by sami on Dec 10, 2009 11:43 AM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting Gravatar...
Giuliano and Michael you are great you have eliminated my biggest trouble :) weldone and keep it up please
Left by Mansoor on Jun 13, 2011 6:06 AM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting 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.
Left by Ali on Jun 27, 2011 9:17 AM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting 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
Left by Alejandro on Nov 12, 2011 1:05 PM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting Gravatar...
Thanks This Info was so Important For Us..!
Left by Lovel on Dec 19, 2011 9:09 PM

# re: Html Form inside ASP.Net page causes no postbacks
Requesting Gravatar...
Please, how to put html form into separate page and inserted into IFRAME on the main asp.net form. ? ?
Left by mohamed on Jul 10, 2013 8:08 AM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net