Tuesday, May 18, 2004

Under ASP normally we you use response.redirect("webform2.asp") to go to another page.  This could also be used in ASP.Net. 

Well, Response.Redirect simply sends a message down to the browser, telling it to move to another page.  Server.Transfer is similar in that it sends the user to another page with a statement such as Server.Transfer("WebForm2.aspx"). However, the statement has a number of distinct advantages and disadvantages.

  1. Transferring to another page using server.transfer conserves server resources.  Instead of a redirect it changes the focus on the webserver and transfers the request.
  2. server.transfer also works only on the sites running on the server.  You can't use server.transfer to send the user to an external site.  This can be done only by using response.redirect.
  3. server.transfer maintains the original URL in the browser.
  4. server.transfer has also an optional parameter " preserveForm ".  If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.  This means that you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").

But be aware when using the preserveForm parameter : ASP.NET has a bug whereby, in certain situations, an error will occur when attempting to transfer the form and query string values. You'll find this documented at http://support.microsoft.com/default.aspx?id=kb;en-us;Q316920

The unofficial solution is to set the enableViewStateMac property to True on the page you'll be transferring to, then set it back to False. This records that you want a definitive False value for this property and resolves the bug.

Update :
I forgot to mention the original article.  So
here it is. (Sorry Karl)

5/18/2004 2:16:29 PM (Romance Standard Time, UTC+01:00)  #     |