Solved

asp.net session declaration

Posted on 2008-11-03
7
789 Views
Last Modified: 2013-11-07
i want to store a dataset value in a session variable but keep getting the value returned as false when i try and write it to the page, when i write the dataset value to the page it works fine but trying to store in the session is the problem, i have pasted the code below, i use classic asp more so this is where i am probably going wrong, i know there are 3 different types of session in .net but not sure how write them correctly.

<p><%# Session("finalu") =  DataSet1.FieldValue("UserID", Container) %></p>
<p><%= session("fianlu")%></p>
0
Comment
Question by:ckawebcreation
  • 3
  • 3
7 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22867601
well what language are you using...if it's vb, i think you have to use the Session.Add

if it's c# i think you can just use Session["fadfsd"] =
0
 
LVL 2

Expert Comment

by:vbsquickresponse
ID: 22867816
here code in C#

to store dataset in session  variable and read from session variable to attach into gridview.

Make sure you use this.DataBind() to bind dataset to gridview control
    protected void Button1_Click(object sender, EventArgs e)

    {

        DataSet ds = ProductsDataAccess.GetProductByCategory(1);

        Session["MyDataSet"] = ds;

    }

    protected void Button2_Click(object sender, EventArgs e)

    {

        DataSet ds = (DataSet)Session["MyDataSet"];

        GridView1.DataSource = ds.Tables["Products"];

        GridView1.DataBind();

    }

Open in new window

0
 

Author Comment

by:ckawebcreation
ID: 22868434
hi vbsquickresponse:

i am using vb though??
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:vbsquickresponse
ID: 22868874
Logic would be same only the syntax would be difference...

//set to session variable
Session("varname") = value

//read from session varible
Session.Item("varname")

sorry, not able to paste extact code becz I never worked on vb.net
0
 
LVL 2

Accepted Solution

by:
vbsquickresponse earned 100 total points
ID: 22869082
here first time I tried code in VB.net


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim ds As DataSet = ProductDataAccess.getProductsbyCategoryID(1)
 

        Session("MyDataSet") = ds

    End Sub
 

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim ds As DataSet = Session("MyDataSet")

        GridView1.DataSource = ds.Tables("Products")

        GridView1.DataBind()

    End Sub

Open in new window

0
 

Author Comment

by:ckawebcreation
ID: 22870920
hi vbsquickresponse:

thanks for the code,

couldn't get that working, surely there must be a way of assigning a value to a session by using a simple statement lke <p><%# Session("finalu") =  DataSet1.FieldValue("UserID", Container) %></p>
i can get the value for the session from a Request.QueryString("Username") either from the current page.

i am using a post method on this page so have struggled to access the Request.QueryString("Username") from my next page that is why i am trying to put it in a session variable so i can access it on the next page.

cheers
0
 

Author Comment

by:ckawebcreation
ID: 22871502
got sorted guys, messed around with url params, cheers vbsquickresponse: and silemone:
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Allow space in this pattern 2 46
Help with solving error related to resources file 4 35
Get id from json Data with NewtonSoft 3 31
Problem to error 4 43
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now