General discussion
Thread display: Collapse - |
All Comments
Start or search
Create a new discussion
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
Problem with SessionState/ViewState
I'm trying to use SessionState or ViewState to pass a variable back to the same page so that the same page can pull up different sets of data. This way I don't have to code 1500 different pages. Unfortunately the page has to be refreshed before the values will pass. Unfortunatly I have found several references to this on the net but no solutions. Passing the SessionState to another page works fine but I cannot pass the SessionState or the ViewState immediately back to the originating page. I could due this through the URL but I don't the data visible.
My code is somewhat simple because I wanted to see if this would work before I decided to use it:
dim searchString as string
dim typeString as string
If Not IsPostBack Then
'set sql query
OleDbDataAdapter1.SelectCommand.CommandText
= "SELECT tblBuildings.fldBuilding,
tblBuildings.fldBuildingKey,
tblContacts.fldContactKey,..."
'fill
OleDbDataAdapter1.Fill(PdDataSet1)
Page.DataBind()
Response.Write("Session ID = " &
Session.SessionID & " -- ")
Response.Write("Search String = " & ViewState
("searchString"))
Else
'load viewstate variables
searchString = ViewState("searchString")
typeString = ViewState("typeString")
'set new sql query
OleDbDataAdapter1.SelectCommand.CommandText
= "SELECT tblBuildings.fldBuilding,
tblBuildings.fldBuildingKey,
tblContacts.fldContactKey,
tblDepartments.fldPrimaryKey FROM
tblBuildings..."
'fill
OleDbDataAdapter1.Fill(PdDataSet1)
Page.DataBind()
Response.Write("Search String = " & ViewState
("searchString"))
End If
End Sub
Private Sub searchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchButton.Click
typeString = searchText.Text
ViewState("typeString") = typeString
Session.Add(typeString, typeString)