Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a page WebControls.aspx. I have some textBox in that page. I want to show that data in other page (Results.aspx) when the user click a button. I have this code but not working...

What I have tried:

'WebControls.aspx
   Private Sub WebControls_Load(sender As Object, e As EventArgs) Handles Me.Load
       If IsPostBack Then
           Dim firstName As String = firstNameTextBox.Text
           Session.Add("Όνομα: ", firstName)
           Session.Add("Επώνυμο: ", lastNameTextBox.Text)
           Session.Add("E-mail: ", emailTextBox.Text)
           Session.Add("Τηλέφωνο: ", phoneTextBox.Text)
           Session.Add("Βιβλίο: ", booksDropDownList.SelectedItem.ToString)
           Session.Add("Λειτουργικό Σύστημα: ", osRadioButtonList.SelectedItem.ToString)


           'Dim ar As New ArrayList()
           'ar.Add("Όνομα: " & firstNameTextBox.Text)
           'ar.Add("Επώνυμο: " & lastNameTextBox.Text)
           'ar.Add("E-mail: " & emailTextBox.Text)
           'ar.Add("E-mail: " & phoneTextBox.Text)
           'ar.Add("Βιβλίο: " & booksDropDownList.SelectedValue)
           'ar.Add("Λειτουργικό Σύστημα: " & osRadioButtonList.SelectedValue)
           'Session("InputData") = ar
       End If

   End Sub


'Results.aspx
    Private Sub Results_Load(sender As Object, e As EventArgs) Handles Me.Load
        For Each keyName In Session.Keys
            outputLabel &= (keyName & Session(keyName))
        Next
        'Dim ar As New ArrayList()
        'ar = Session("InputData")
        'outputListBox.DataSource = ar
        'outputListBox.DataBind()

    End Sub
Posted
Updated 8-Apr-19 6:32am

You have to cast the data to it's appropriate type, even if it's a string. In your case, it's an ArrayList of strings, so you have to cast it appropriately.
 
Share this answer
 
Seems like you commented out your code. Also, you need to put your code inside your Button's Click event instead of Page_Load. You can try something like this:

VB
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub          
           Dim ar As New ArrayList()
           ar.Add("Όνομα: " & firstNameTextBox.Text)
           ar.Add("Επώνυμο: " & lastNameTextBox.Text)
           ar.Add("E-mail: " & emailTextBox.Text)
           ar.Add("E-mail: " & phoneTextBox.Text)
           ar.Add("Βιβλίο: " & booksDropDownList.SelectedValue)
           ar.Add("Λειτουργικό Σύστημα: " & osRadioButtonList.SelectedValue)
           Session("InputData") = ar
           Response.Redirect("Result.aspx")
End Sub


Then in your Result.aspx page, you can reference the data like this:

VB
Private Sub Results_Load(sender As Object, e As EventArgs) Handles Me.Load
       If Session("InputData") IsNot Nothing Then
    		Dim data As ArrayList = CType(Session("InputData"), ArrayList)
		    outputListBox.DataSource = data
        	outputListBox.DataBind()
	End If   
End Sub


Note that Sessions is just one of the option to transfer data from one page to another. You can also use either:

1. Server.Transfer() method
2. PostBackURL of a Button
3. QueryStrings
4. POST Request
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900