473,763 Members | 3,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

"Lloyd Sheen" <a@b.cwrote in message
news:uL******** ******@TK2MSFTN GP06.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=Sess ion["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 1209

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:Or******** ******@TK2MSFTN GP05.phx.gbl...
"Lloyd Sheen" <a@b.cwrote in message
news:uL******** ******@TK2MSFTN GP06.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=Sess ion["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=(Dat aSet)Session["Store"]'

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

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

sorry

myVariable=(Dat aSet)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.P age

public class clsStandardPage : System.Web.UI.P age
{
protected clsBrowserSessi on _objBs;
protected override void OnPreInit(Event Args e)
{
Response.CacheC ontrol = "no-cache";
Response.Expire s = -1;
_objBs = (clsBrowserSess ion)Session["BrowserSession "];
if (_objBs == null)
{
_objBs = new clsBrowserSessi on();
Session["BrowserSession "] = _objBs;
}
base.OnInit(e);
}
}

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

.........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._sFirstN ame;
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
2455
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 variables and all of them are being stored into session and accessed from session and individual session object. Example: Session = "XYZ", Session=100, Session="NAME", etc.
9
2385
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 - perhaps I'm just not very smart or perhaps MS is making this too hard for us sql bunnies to understand - I dunno, but I'd really appreciate someone explaining what I'm doing wrong here & perhaps suggest a better approach.. I'm familiar with use of...
3
2034
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 handles are stored in session variables. This works fine without a problem. Ported it to ASPX, accessing the same DCOM server from code behind pages. Still, usually no problems. However sometimes I'm seeing an error stating that the DCOM handle...
8
3177
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, if a user logs onto the website, a user object is created that stores their full name, email address, street address, phone, etc. This object also has methods to do 'other' things such as validations, counters,
13
1912
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") + 1 Why? Thanks Dee.
15
2419
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 1000 items it might use 100KB. How do I measure the amount of memory used once the class is loaded? Thanks! -- Joe Fallon
13
1758
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 properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object? Thanks, Jerry
20
4042
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 tells me if a variable has changed, give me the original and current value, and whether the current value and original value is/was null or not. This one works fine but is recreating the same methods over and over for each variable type. ...
4
4402
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 to $user $_SESSION = serialize($user);
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9389
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9828
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2797
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.