homepage Welcome to WebmasterWorld Guest from 54.167.11.16
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Programmatically POSTing a form from .NET
...and ways to get around the impossibility of it.
Gibble




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

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




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

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




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

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




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

Correct. You cannot nest forms in HTML.

andyll




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

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




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

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]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved