Name

Transfer

Synopsis

Server.Transfer(Path)
Server.Transfer(Path, preserveForm)

Discontinues execution of the current page and transfers execution to the page specified by the Path argument. This allows control of an application to be redirected to the page specified by the Path argument without any response being sent to the client.

In contrast to the Execute method, which returns control to the page in which it is called once the page specified in the Execute method finishes processing, the Transfer method does not return control to the calling page.

Parameters

Path

A String variable containing the path to the page to which execution will be transferred.

preserveForm

A Boolean variable that indicates whether the Form and QueryString collections should be cleared before transferring control to the page that the Path argument specifies.

Example

The code example declares a string variable containing the name of the page to transfer control to, and then calls Server.Transfer. Note that the call that sets the Message.Text property will never be executed.

Sub Page_Load(  )
   Dim Url As String = "CreateObject.aspx"
   Server.Transfer(Url)
   Message.Text = "This code will never be executed!"
End Sub

Notes

The ability to clear the Form and QueryString collections prior to passing control to the page that the Path argument specifies is new in ASP.NET. This is convenient for passing control to pages that you did not create and that might break if they encounter unexpected values, or if you want to ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.