Welcome to WebmasterWorld Guest from 54.226.241.8

Forum Moderators: ocean10000

Message Too Old, No Replies

Programmatically POSTing a form from .NET

...and ways to get around the impossibility of it.

     

Gibble

2:54 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, we've run into an instance where we have a 1.1 .NET app, and a classic ASP app that technically are the same site, some code is old, some older. At this point in time, we can't update it all to 2.0, though, I'm sure in the future that will be done.

Anyhow, one of our order pages currently accepts values via a form POST, we don't want to use GET for security reasons (prevents users from easily just messing with the posted data). So, the problem arises, when I'm at a .NET page the user arrives at through email, it uses forms authentication (not that it matters, but that's why this is a mix of .net and classic asp) and once the user is logged in, we want this page, to redirect the user to a step in the middle of the order process.

Seems simple, but that page, as I mentioned expected POST data. I can't do a response.redirect, because that would be a GET request with the variables on the query string. I don't want to dynamically build a form and post it with java script as that's not reliable.

Ultimately, I've resorted to a HTTPWebRequest/HTTPWebResponse solution, that seems to work great, I built the POST request, read the response, and throw the result into a literal on the page. I am now at the proper spot in the order process, everything looks golden...then I hit submit.

*sigh*

The form doesn't post to the next page, it does a post back because I'm still technically viewing a .NET page and have a structure as follows:


<form name="Form1" method="post" action="thispage.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="foo" />
<form action="NextPage.asp" method="post">
Various inputs and other form elements
</form>
</form>

This is infuriating.

Any ideas?

Gibble

3:57 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I noticed, if I change the classic forms submit to a regular button, and try to alert(document.forms[1]); it doesn't find the form...? forms[0] is the .NET postback form...so why isn't mine in the DOM? Is it because it's nested?

Gibble

4:00 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, that's it.

<!--Works-->

<form id="1">
</form>
<form id="2">
<input type="button" onclick="alert(document.forms[0]);alert(document.forms[1]);">
</form>


<!--Does not work-->

<form id="1">
<form id="2">
<input type="button" onclick="alert(document.forms[0]);alert(document.forms[1]);">
</form>
</form>

mattglet

8:49 pm on Aug 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Correct. You cannot nest forms in HTML.

andyll

5:02 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



Gibble,

You can do a post through Server Side code.

Search on RemotePost and you should be able to find a class that was built to do this.

My checkout button is just a regular ImageButton post back to my .Net page which writes the cart to my DB and then posts the data to Paypal.

Andy

duckhunter

1:30 am on Aug 15, 2007 (gmt 0)

10+ Year Member



Had the same problem with a site and used a new attribute available in the 2.0 Framework. asp:buttons can now have an attribute called PostBackURL [msdn2.microsoft.com]
 

Featured Threads

Hot Threads This Week

Hot Threads This Month