Pronunciation / adjective
Bringing something good and unforseen.
    Skip Navigation Links > Code Repository
   

Use Server.Transfer to pass values from one page to another



 
Return

Use Server.Transfer to pass values from one page to another

If you don't want to use session variables or have data appear in the query string of your page then utilizing the Server.Transfer method for moving from one page to another is a great way to make one page's properties available to another.

On your first page create a public property that accesses the value you want to make accessible to other pages.
  1. Public ReadOnly Property UserId() As Int32
  2. Get
  3. '---Where _UserId is a private variable on the page
  4. Return _UserId
  5. End Get
  6. End Property


Use Server.Transfer to execute the page transferred to.
  1. Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
  2. Server.Transfer("page2.aspx")
  3. End Sub


Recreate the page1 object on page2 and get the user id.
  1. Private _UserId As Int32
  2. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3. If Not IsPostBack Then
  4. Dim Page1 As Page1 = CType(Context.Handler, Page1)
  5. _UserId = Page1.UserId
  6. End If
  7. End Sub


Return
Microsoft Certified Professional   © 2018 Fortunate.  All rights reserved.
contact: justin@aboutfortunate.com