Solved

asp.net session declaration

Posted on 2008-11-03
7
799 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to share My.Settings in multiple application instances ? 7 48
SSIS Start 2 37
asp.net mvc 2 32
vb.net convert long time to mm:ss 23 20
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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