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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dataset in session variable problem

Status
Not open for further replies.

logi2000

Programmer
Jun 17, 2003
221
CR
hi. i am storing a dataset in a session variable like this.

Session["myds"] = ds ;

then i use a button to call another page. like this.
Response.Redirect("page2.aspx") ;

in the load form of page2.aspx,
i retrieve the session variable like this:

datagrid1.DataSource = (DataSet)Session["myds"];
datagrid1.DataBind();

but the datagrid does not show any rows, and when i do a quickwatch to the session variable containing the data set, the system reports that it is null.

what can the problem be ?
 
Session variables are automatically discarded after they are not used for the time-out setting that is specified in the Web.config file
Code:
<sessionState mode="InProc" 
  stateConnectionString="tcpip=127.0.0.1:42424" 
  sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strong password>" 
  cookieless="false" 
  timeout="20" />

Make sure your pages are in the same application

Your session is an Object, so you have to do a CType..

Code:
Private Sub Page_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
    If IsPostBack Then
        DsNorthwind1 = CType(Session("dataset"), DsNorthwind)
    Else
        SqlDataAdapter1.Fill(DsNorthwind1)
        Session("dataset") = DsNorthwind1
        DataBind()
    End If
End Sub
 
with the response redirect is working now, i found the bug.

now i have a problem. that if i use a vbscript, or javascript to call the second page, the session variable is empty, when i try to acceess its value on the second page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top