Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session variable losing values 1

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
I have a click button in my page and when I click it more than one time the value for session variable losing the stored value. anybody has an idea why this is happening. I am getting the value for session varialbe form another page.thanks

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

        Dim TmReview As String
        TmReview = Session("TmId")
        'Response.Write("Here is the value" & TmReview)

        If Not IsPostBack Then

            Label1.Text = "Select Review Participants for TM " & TmReview
            MemoReviewers()
            CheckReviewers(TmReview)
        End If
    End Sub




 Sub CheckandUpdateDb()
        Dim strReviewrsId As String = ""
        For Each li As ListItem In cblReview.Items
            If li.Selected Then
                strReviewrsId = strReviewrsId & li.Value & ","
            End If
        Next
        strReviewrsId = Left(strReviewrsId, Len(strReviewrsId) - 1)
        Session("TmReviewrsId") = strReviewrsId
        Dim TmReview As String
        TmReview = Session("TmId")


        Dim strTechMemoConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\DataBase\techmemo.mdb") & ";"
        Dim MyTechMemoConn As New OleDbConnection(strTechMemoConn)

        Dim strStringBuilder As StringBuilder
        strStringBuilder = New StringBuilder
        With strStringBuilder
            .Append("SELECT * from tbTM WHERE TM =" & "'" & TmReview & "'")
        End With

        Dim cmdReview1 As OleDbCommand = New OleDbCommand
        cmdReview1.Connection = MyTechMemoConn
        cmdReview1.CommandType = CommandType.Text
        cmdReview1.CommandText = strStringBuilder.ToString
        Dim adReview1 As New OleDbDataAdapter(cmdReview1)
        Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adReview1)
        Dim dsReview1 As New DataSet
        adReview1.Fill(dsReview1, "ReviewList")

        Dim count As Integer = dsReview1.Tables("ReviewList").Rows.Count
        Response.Write(TmReview)
        Response.Write(count)

       
    End Sub
 
can you get the value from query string like this?
Dim TmReview As String = Context.Request.QueryString("id")

I am going to try this and see the value will be retained until the whole process for the app. is completed.
 
You can get the value from query string.
The session expires. So before accessing an item, check it is not nothing, like:
Code:
if Object.Equals(Session.Item("TmId"), Nothing) then
 
Thank you TipGiver, I get the value using the query string.I really appreciate for taking time to explain it for me. this way seems to work for me.

Dim TmReview As String = Context.Request.QueryString("id")

 
You should do the same existance check for the querystring too!

Depending on what you want to transfer, querystrings can be great. They exist for ever in the url, but the user can change a value and hit refresh. You also have a limit off about 256 chars (?) in the url (i think that is the GET)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top