www.webdeveloper.com
Results 1 to 2 of 2

Thread: Sessions

  1. #1
    Join Date
    Sep 2011
    Posts
    5

    Sessions

    I cannot for the life of me figure out what I am doing wrong.
    I want to capture a session for a checkbox, and if checked, send that to another page.

    Code as follows:

    First Page:
    Code:
    Private Function GetContact() As SortedList
            If Session("Contact") Is Nothing Then
                Session.Add("Contact", New SortedList)
    
            End If
            Return CType(Session("Contact"), SortedList)
        End Function
    
        Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    
    
            If chkContact.Checked = True Then
                Session.Add("Contact", New SortedList)
            Else
                chkContact.Checked = False
            End If
            Response.Redirect("results.aspx")
        End Sub
    Second Page:
    Code:
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            contact = Me.GetContact
            If Not IsPostBack Then
                Me.DisplayContact()
                Me.SetFocus("lblContact")
            End If
        End Sub
    
        Private Function GetContact() As SortedList
            If Session("Contact") Is Nothing Then
                Session.Add("Contact", New SortedList)
    
            End If
            Return CType(Session("Contact"), SortedList)
    
        End Function
        Private Sub DisplayContact()
            If Not IsPostBack Then
                lblContact.Text = ""
            Else
                lblContact.Text = "We will contact you within 24 hours"
            End If
    
        End Sub

  2. #2
    Join Date
    Sep 2011
    Posts
    3
    hi,
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim chkvalues As ArrayList = New ArrayList()

    For Each chkBoxListItem As ListItem In CheckBoxList1.Items
    If (chkBoxListItem.Selected) Then
    chkvalues.Add(chkBoxListItem.Value)
    End If
    Next chkBoxListItem

    Session("CheckedItems") = chkvalues
    Response.Redirect("Default2.aspx")

    End Sub



    Then for retrieving checked values in the 2nd page, use something like this :

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not (Session("CheckedItems") Is Nothing) Then
    Dim chkvalues As ArrayList = CType(Session("CheckedItems"), ArrayList)
    For Each chkBoxListItemValue As String In chkvalues
    Response.Write(System.Environment.NewLine + chkBoxListItemValue)
    Next chkBoxListItemValue
    End If

    End Sub

    website development services | Web development company

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles