473,396 Members | 1,893 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.

How to retrieve a session value

In vb I can retrieve a session variable in a web site as follows.
Dim myvar as string
MyVar = Session.Item("VarName").ToString

But In C# there is no item property to use.
How do you retrieve the value of a session item in C#?

Thanks for any help
Bob
May 2 '07 #1
3 9861

Session["VarName"]

its called an indexer. where vb.net adds .Item() to get to the indexer.

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:e$**************@TK2MSFTNGP06.phx.gbl...
In vb I can retrieve a session variable in a web site as follows.
Dim myvar as string
MyVar = Session.Item("VarName").ToString

But In C# there is no item property to use.
How do you retrieve the value of a session item in C#?

Thanks for any help
Bob


May 2 '07 #2
"Robert Dufour" <bd*****@sgiims.comwrote in message
news:e$**************@TK2MSFTNGP06.phx.gbl...
In vb I can retrieve a session variable in a web site as follows.
Dim myvar as string
MyVar = Session.Item("VarName").ToString

But In C# there is no item property to use.
How do you retrieve the value of a session item in C#?
The equivalent of 'Item' in C# is the class indexer, which you access
using square brackets:

MyVar = Session["VarName"].ToString();
May 2 '07 #3
On May 2, 2:53 pm, "Robert Dufour" <bduf...@sgiims.comwrote:
In vb I can retrieve a session variable in a web site as follows.
Dim myvar as string
MyVar = Session.Item("VarName").ToString

But In C# there is no item property to use.
How do you retrieve the value of a session item in C#?

Thanks for any help
Bob
This is an Indexer which is handled by adding the Item property in VB,
these constructs are natively handled in C# and you can access your
session value as follows:
string myVar = Session["VarName"];

Hope this helps.

May 2 '07 #4

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

Similar topics

2
by: AlBruAn | last post by:
An application I'm helping develop transmits XML to an ERP and receives an XML statement showing the result of the transmittal to the ERP. I've pasted a copy of one of the response XML statements....
2
by: epigram | last post by:
I'm responding to a button click event on an asp.net web form. I then need to retrieve the value from a TextBox control and I want to compare it against the control's previous value to see if it...
2
by: Kash | last post by:
Hi everybody I have a session on my vb.net web applications first page to store an one dimensional array: dim myAry(2) As String myAry(0) = xVal myAry(1) = yVal...
2
by: Frank | last post by:
Can I do this? I add a session var in C# and ultimatly want to pass it into a vbscript client side activeX control. This is what I have so far but get " Object Required:'name2' " error. Can...
1
by: whidbey | last post by:
Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books...
0
by: whidbey | last post by:
Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books...
4
by: kang jia | last post by:
hi i am doing mailinglist currently. the code in my first page is like this : : <html> <head> <link rel="stylesheet" type="text/css" href="gallery.css" /> <script language="JavaScript"> ...
2
by: Cramer | last post by:
Using ASP.NET 3.5... As far as I know, any time we store a value in application or session state, it is stored as a humble 'object' type rather than it's "real" type. For example, if we want...
4
by: Michael | last post by:
I am using Web Developer Express 2005. I created a little form to add some content to a database. I keep the formview default mode in the insert mode. The values are being added to the database...
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
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...
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
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.