400_the_cat
400_the_cat

Reputation: 883

ASP.NET - Populate a page with input entered from a previous page

on my website I have an "Enroll" page where users submit some basic information, there's some basic validation on that page then the user is taken to an "Enrollment Confirmed" page (which i don't want to display the info from previous page). On the confirmation page there is link to a "Print Enrollment Confirmation" page which, on this page, I want to contain the information entered from the "Enroll" page. So basically, I want the input entered on "Page 1" put into labels on "Page 3". I've seen some examples of transferring information from "Page 1" to "Page 2" but I have an extra page users need to go through before hitting the page with their previously entered data.

Can someone give me an explanation on how I could do this without using query strings? Thank you.

Upvotes: 1

Views: 929

Answers (4)

Mike
Mike

Reputation: 5499

You could create an class with properties for each form field then store it in the session. Then after you populate what you need on page 3 remove it from the session.

Example

Class:

 <Serializable()>
Public Class Input
    Private _FirstName As String = String.Empty
    Private _LastName As String = String.Empty

    Public Property FirstName As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property

    Public Property LastName As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property

    Public Sub New()
    End Sub
End Class

Storing data:

Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    Dim FormData As New Input()
    FormData.FirstName = txtFirstName.Text
    FormData.LastName = txtLastName.Text
    Session("InputData") = FormData

End Sub

Retrieving it:

   If Not IsNothing(Session("InputData")) Then
       Dim FormData As Input = DirectCast(Session("InputData"), Input)
       txtFirstName.Text = FormData.FirstName
       txtLastName.Text = FormData.LastName
       Session.Remove("InputData")
   End If

Upvotes: 4

Faran
Faran

Reputation: 11

I would store the values in hidden input fields on page 2 and if page 3 is called as a form submit, then the values will be available through Request.Form.

Upvotes: 0

E.J. Brennan
E.J. Brennan

Reputation: 46839

This pretty much sums up your choices:

http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx

Upvotes: 0

Brian Mains
Brian Mains

Reputation: 50728

You could use the button.postbackurl property to post the data to another page:

http://msdn.microsoft.com/en-us/library/ms178140.aspx

In the intermediary pages, you could store the data in hidden fields from page 1, so the data would be in the posted results for page 3, when another button posts the data from page 2 to page 3.

HTH.

Upvotes: 1

Related Questions