ASP.NET: Adding a form to post to another site
I have an ASP website and I need to add a form that will post to another site and open in another window. I can't use JavaScript (which would make it easy). The issue is that I can only post a few fields to the other site, so I can't just add the inputs and redirect the post back to the other site because all of the ASP info would be posted, too.
Basically, I need to get the following code working (or something equivalent), but I can't add the form tag because of the ASP form.
<form id="frm_post" 开发者_StackOverflowaction="https://anothersite.com" target="_blank" method="POST">
<input type="hidden" id="accountnumber" name="accountnumber" value="123456" />
<input type="submit" value="Submit" />
</form>
All the fields will be hidden, so it will basically look like a link, but it will be a post request with the specified fields/values.
Thanks.
Instead of nesting the form try moving the inner form tag to be outside/after the asp.net form. Then use CSS to reposition the 2nd form so that it looks like it is in the same position visually as it currently does.
This actually works:
Add a blank <form></form>
immediately before the form you would like to submit (frm_post
in your case)
The </form>
tag "tricks" asp into not including your new form in its self-postback-viewstate-mess, allowing your form to actually post, and the asp form to still function properly. A little hacky, but totally fixes it.
In my opinion, The two-forms problem is one of the great Achilles Heels of ASP.net
You can not place nested form tags in asp.net. you can place them beside each other but not nested in other form. you should change your forms structure to correct this problem.
精彩评论