472,378 Members | 1,503 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 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 32086
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.