473,396 Members | 1,764 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,396 software developers and data experts.

Reference a session object

I have a VB .NET web application.

I have a structure of data I want to keep throughout the whole
session. Now I do it like below.

Structure SMyStruct
Dim number as Integer
......
End Structure
Private Sub Button_Go_Click(....) ....
Dim S As SMyStruct = Session("MyStruct")
S.number = 7
Session("MyStruct") = S
End Sub

This works, but not very efficient when the structure is big. The data
first gets copied from the Session then modified and then stored back
to the Session.

And I do NOT want to use the syntax
Session("MySessionObj").number = 7
for obvious reasons.

So is there any trick around that lets me get a reference to a session
variable so I can modify my structure members directly.
Nov 18 '05 #1
2 910
Hi Lars:

I'd strongly suggest you use a reference type. Define your type as a
Class instead of a Structure and you'll find the performance is better
and there will also be no need to copy the value back into the
session.

A Structure is a value type. The runtime has to be box and unbox the
value to move in and out of the session collection - there is no
avoiding it. Boxing is the process of turning a stack based value type
into a heap object.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 31 Oct 2004 07:01:17 -0800, la***********@mail.nu (Lars Dahlback)
wrote:
I have a VB .NET web application.

I have a structure of data I want to keep throughout the whole
session. Now I do it like below.

Structure SMyStruct
Dim number as Integer
......
End Structure
Private Sub Button_Go_Click(....) ....
Dim S As SMyStruct = Session("MyStruct")
S.number = 7
Session("MyStruct") = S
End Sub

This works, but not very efficient when the structure is big. The data
first gets copied from the Session then modified and then stored back
to the Session.

And I do NOT want to use the syntax
Session("MySessionObj").number = 7
for obvious reasons.

So is there any trick around that lets me get a reference to a session
variable so I can modify my structure members directly.


Nov 18 '05 #2
Thank you Scott!

Also found a another way myself (below) but your way is the one.

Structure SMyStruct
Dim number as Integer
......
End Structure

Private Sub Button_Go_Click(....) ....
Go(Session("MyStruct"))
End Sub
Private Sub Go(ByRef S as SMyStruct)
S.number = 7
End Sub
Nov 18 '05 #3

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

Similar topics

7
by: kon george | last post by:
Can somebody assist. I build this code on a dev laptop and copied across the entire code to a Windows 2003 server with 1.1 framework. It is basic ASP.NE T that uses web service for SQL Server...
7
by: TS | last post by:
I was under the impression that when you get a reference to an object, then update that reference, the object gets updated. Apparently this isn't the case using session? code (note at this point...
4
by: Steve Richter | last post by:
this code compiles ok: public string AssureAnonUID( ) { if (Session == null) Session = Guid.NewGuid(); return Session.ToString(); } but this code does not: public string AssureAnonUID( )
3
by: Alexander Widera | last post by:
hi, i have the following problem in the following code: Basket basket = (Basket) Session; if (basket.isEmpty) { ........... }
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
0
by: Richard Gregory | last post by:
Hi, I have the wsdl below, for an Axis web service, and when I select Add Web Refernce in Visual Studio the proxy is missing a class representing the returnedElementsType (see reference.cs below...
0
by: =?Utf-8?B?SkhhbGV5?= | last post by:
Our system is: IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram Windows Server 2003 SP2 IIS 6.0 SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server) Windows Server 2003 SP2 SQL...
4
by: =?Utf-8?B?QWxla3MgS2xleW4=?= | last post by:
When I call sub in VB I can sent value of variable or reference to this value. The question is. Suppose I have class public class AA .... end class and declare object of this class dim objAA as...
0
markrawlingson
by: markrawlingson | last post by:
Hello, So I've got a list of functions written in ASP Classic which I include into every page within my application(s). This file is getting quite big and in most scenarios needs to be called 4-5...
2
by: swathi amireddy | last post by:
Hi, Im working on migration of one proj from .Net1.1 to2.0 in that some pages are unble to run; on Debug i havent obeserved ani error at any line but in IE .getting this error ...
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:
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.