Solved

asp.net session declaration

Posted on 2008-11-03
7
785 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

13 Experts available now in Live!

Get 1:1 Help Now