I add a form from code behind to asp:PlaceHolder
control.
When I add form to placeholder
<form>
tags are missing.
Asp.net removes it from some reason.
But I have found workaround for this. I have added (empty form):
<form></form>
<form... my form code that comes from code behind...
And this works fine in all browsers except IE!
Any idea how to workaround this in IE.
(Maybe this is important) This form is actually a PayPal button code and I get it from data source.
I need to add 10 buttons on page:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" ...
One of the dissadvanced of the asp.net webforms is that only one asp.net form is allowed in a normal asp.net page. One form that have the runat="server"
and inside that form only the asp.net controls correctly work and cooporate with the code behind.
However you can break that - but not continue to have the same asp.net functionallyty. What you can do is to use a LiteralControl and direct render on the page the PayPal button code and only before just close the global form by using the </form>
. Only the close just before add the new ones.
Now the moment you do that, you must forget the post back on the same page and actually have it only for post to PP. The only way to have some asp.net page functionallyty is to keep it before the first form close, and set on web.config the option to keep the validation on top.
So you start with
<form name="aspnetForm" method="post" action="/ui/login.aspx?ReturnUrl=General.aspx" >
... some controls that post back to aspx page
</form>
and you end up with
<form name="aspnetForm" method="post" action="/ui/login.aspx?ReturnUrl=General.aspx" >
... some controls that post back to aspx page
... up to here maybe the buttons will work for the page, after that not any more
</form> //<---- added by you
// follow the PayPal buttons
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" ... >
</form>
// second button, etc
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" ... >
</form>
// now this close form is orphan....
</form>
Alternative you can make post redirect, but require a lot more code and a middle page that create the PayPal post data on code behind. Here is an example http://www.codeproject.com/Articles/37539/Redirect-and-POST-in-ASP-NET
The same trick you can do it with javascript, create a form using javascript on the fly and post that to the paypal button, all on the same page with javascript.
I have use all that techniques, all of them works.