473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Re: Using Session variables without casting them to a new object

"Lloyd Sheen" <a@b.cwrote in message
news:uL**************@TK2MSFTNGP06.phx.gbl...
Create a page level variable of type DataSet. Then on load or whenever
you need it. If you use a property you can do something like:
DataSet myVariable;

In the property get:

if (myVariable ==null)
{
myVariable=Session["Store"]'
}
return myVariable;
Surely that will throw an exception because you're trying to populate a
DataSet variable with an object datatype...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #1
3 1189

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:Or**************@TK2MSFTNGP05.phx.gbl...
"Lloyd Sheen" <a@b.cwrote in message
news:uL**************@TK2MSFTNGP06.phx.gbl...
>Create a page level variable of type DataSet. Then on load or whenever
you need it. If you use a property you can do something like:
DataSet myVariable;

In the property get:

if (myVariable ==null)
{
myVariable=Session["Store"]'
}
return myVariable;

Surely that will throw an exception because you're trying to populate a
DataSet variable with an object datatype...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
sorry

myVariable=(DataSet)Session["Store"]'

Jun 27 '08 #2
"Lloyd Sheen" <a@b.cwrote in message
news:uE**************@TK2MSFTNGP06.phx.gbl...
>>if (myVariable ==null)
{
myVariable=Session["Store"]'
}
return myVariable;

Surely that will throw an exception because you're trying to populate a
DataSet variable with an object datatype...

sorry

myVariable=(DataSet)Session["Store"]'
Yeah, but that's precisely what the OP is trying to avoid, at least, based
on the thread title...

Not possible, IMO...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #3
Here is how i do staff hope it will help you on your quest to perfect .NET
application :)

1. Create new class clsBrowser for example like this
public class clsBrowser
{
public int _iUserId;
public string _sFirstName;
public string _sLastName;
public clsShoppingCart _shoppingCart = null;
}
2. Create new class clsStandardPage : System.Web.UI.Page

public class clsStandardPage : System.Web.UI.Page
{
protected clsBrowserSession _objBs;
protected override void OnPreInit(EventArgs e)
{
Response.CacheControl = "no-cache";
Response.Expires = -1;
_objBs = (clsBrowserSession)Session["BrowserSession"];
if (_objBs == null)
{
_objBs = new clsBrowserSession();
Session["BrowserSession"] = _objBs;
}
base.OnInit(e);
}
}

3. Modify web.config a little.
<pages pageBaseType="clsStandardPage">

.........done.....

Now all your pages will be derived from clsStandardPage. All your page's
code will have access to _objBs variable.

no code like that
string sFirstName = (string)Session["FirstName"];
now it's
string sFirstName = _objBs._sFirstName;
Hope you got an idea...
1. It actually reduces a mess if you have a lot of Session variables.
2. No mispells anymore when working with Session object.
3. Code is type safe.
4. Code is faster since everytime you do Session[".."] it's a look up in
hashtable. Plus boxing/unboxint of value types....
George.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Abhilash.k.m | last post by:
This is regarding the session management using Out of proc session management(SQL SERVER). Among the samples below which one is better to set the session? 1. There are 20 session...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
3
by: Alex | last post by:
I'm having a problem porting an ASP solution to ASPX. In the ASP solution I'm accessing a DCOM server, create sub DCOM objects and call functions from VB script on the ASP pages. The DCOM object...
8
by: Dave Wurtz | last post by:
All, I'm new to ASP development and I have a basic design question: Is it ok to store business objects to session variables or is there a better way to keep object information? For example,...
13
by: dee | last post by:
Hi My code complies the following line: Session("passed") = 1 but puts wiggly error line under the second Session("passed") in the following expression: Session("passed") = Session("passed") +...
15
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with...
13
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
4
by: AndreH | last post by:
Good day, I have the a bit of an issue with retrieving an object from php's session. I set a session variable "user" from the class User as follows: $user = new User(); // ... do some stuff...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.