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

storing array in session variable

Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?

Nov 17 '05 #1
4 32271
hi,

My advise is that you should read an introductory book to c# , this is
based on both your questions.

This will solve your problem:
txtmyarrat.Text = ((string[])Session["myarray"])[0];

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"mechweb" <me*****@yahoo.com> wrote in message
news:uo*************@TK2MSFTNGP09.phx.gbl...
Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?


Nov 17 '05 #2
Hi,

you've got to cast it back to an array type.

txtmyarray.Text = (string)((Array)Session["myarray"])[0]
or
txtmyarray.Text = ((string[])Session["myarray"])[0]

Christof

"mechweb" <me*****@yahoo.com> schrieb im Newsbeitrag
news:uo*************@TK2MSFTNGP09.phx.gbl...
Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?


Nov 17 '05 #3
In message <uo*************@TK2MSFTNGP09.phx.gbl>, mechweb
<me*****@yahoo.com> writes
Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?


Session["myarray"] is returning type object. Cast it to string[] before
trying to access it as such.

--
Steve Walker
Nov 17 '05 #4
Thanks for the quick response, that did it!

"Christof Nordiek" <cn@nospam.de> wrote in message
news:u1**************@TK2MSFTNGP14.phx.gbl...
Hi,

you've got to cast it back to an array type.

txtmyarray.Text = (string)((Array)Session["myarray"])[0]
or
txtmyarray.Text = ((string[])Session["myarray"])[0]

Christof

"mechweb" <me*****@yahoo.com> schrieb im Newsbeitrag
news:uo*************@TK2MSFTNGP09.phx.gbl...
Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?



Nov 17 '05 #5

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

Similar topics

15
by: | last post by:
Hi, I want to do things this way: I have a bunch of stuff that I want to keep track of while a user is connected to the site. Maybe 50 little peices of information. So I know I can make 50...
4
by: GJones | last post by:
Is there away to capture a session variable value from IIS and use it in a SQL 2000 trigger with out passing it as a part of a string query. I just want to capture it somehow systemically. ...
3
by: Neil Jarman | last post by:
Hi, I need to create an array with a session variable. According to thebook I'm using, the following should work, but if fails: for each key in request.QueryString if left(key,6) = "cboRun"...
0
by: Sandra | last post by:
I am using a VB6 COM object with an asp.net project. I am storing the COM object in a session variable but am having a problem accessing the COM object from the session variable. I am getting...
3
by: Tillman Erb | last post by:
Let's assume a database with a parent table and a child table in a one-to-many relationship, respectively. I have a DataList control on page P that displays values from the parent table. Each row...
4
by: MrBiggles | last post by:
Here's the sitch: I read in a csv file with 60000 lines (20 fields per record), and store the data to a local array. The file is read in and stored just fine and pretty quick. Now, if I try to...
5
by: TRB_NV | last post by:
I'm losing information from my Session when I change pages or start the same page over again. I simplified the code so the example is really clear. The sample code that follows is supposed to...
1
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.