server.transfer() saved my asp

September 25, 2006 under ASP, IIS, Programming

At work, I’m near completion of an ASP ecommerce project. Up to this point in my life, I had never coded with anything other than Perl or PHP running on Apache when working on web-based projects that required dynamically generated content. So this project stole my ASP-on-IIS virginity; this is a good thing.

Server.Transfer() is a useful method that I stumbled upon by accident. I had an ASP script that was called from a POSTed web form. Said script took the form data, did some stuff, and needed to post one of two possible forms, depending on the data. I knew that out-of-the-box, PHP has no way to accomplish this. I became nauseated, believing that I’d have to generate a new form on the fly, complete with some JavaScript to be called in the BODYs onLoad event so as to post the form automatically. Ugh. Then, a gift from the heavens, “heavens” being a Google query, bestowed Server.Transfer() upon me. I found Response.Redirect() as well, but that totally smacked of PHPs header() function, which won’t submit form variables via a POST request, and would not be of any help.

If we’re on a.asp, which contains a bunch of form elements, and we want to go to b.asp, we can do the following:

< %
   ' Go to b.asp and preserve all of the form elements from a.asp.
   Server.Transfer("b.asp")
%>

Now from b.asp, we can retrieve the form elements that were on a.asp via the Reponse.Form() method. You just have to be careful as to what is already written to the browser prior to calling Server.Transfer() as it won’t be requesting a brand new page like Response.Redirect() would. Server.Transfer() is, thankfully, also available to ASP.NET.

This is probably old hat to all of the ASP veterans out there in Internet land, but it’s new to me and I’m glad that it exists 🙂

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
comments: 0 »