472,981 Members | 1,369 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,981 software developers and data experts.

ArrayList in CSharp

I''ve been working with a CSharp web-site (and am new to it). I have a
javascript function that accepts variables from my CSharp code. It all works
fine, with the exception of one variable type. I created an ArrayList
variable in my CSharp program and it collects the information i need with no
problem. I pass it to my javascript with no problem. Where I'm having a
problem is retreiving the ArrayList values once it's been passed to the
javascript. Since I am not familiar with CSharp and Javascript I am not sure
where to turn for help.

It appears to me that the ArrayLlist was successfully passed to my
javascript function without error, since the remainder of my javascript
works fine. But, when I try to retrieve anything from my array list I have no
luck.

So, If I had the function below, that was accepting an array list as such,
and the array list contains 4 items, how could I display the results in a
window. (My actually purpose is not to display in a window, but I just want
to get somethign working right now).

function CalcTotal(myArrayList)
(
for (i = 1; i < 5; i++)
{
window.alert('myArrayList Value: ' + i + ' - ' + myArrayList(i) );
}
}

My ulimate goal is to scan through the results of the ArrayList to perform
some calculations on a web-page. I've got this part working, but I need to
pass in my answers via an ArrayList.

Any help would be greatly appreciated.
Aug 6 '08 #1
3 3763
I'm actually surprised it lets you carry an ArrayList into javascript!
I've never tried... I generally consider an ArrayList (or rather, a
List<T>) to be a server-side object, not a client-side one.

However, doesn't javascript use square brackets for indexers? Try
myArrayList[i], like you would in C#

Marc
Aug 6 '08 #2
Hi,

On Aug 6, 12:56 pm, Greg <AccessVBA...@newsgroups.nospamwrote:
I created an ArrayList
variable in my CSharp program and it collects the information i need with no
problem. I pass it to my javascript with no problem.
How????
I think you are making a mistake here, that is no possible, AFAIK.
Can you post your page? I'm interested in seeing how you do it.

Besides in your code is myArrayList a function or an array?
I ask because you are using () as in a function
Aug 6 '08 #3
Greg wrote:
I''ve been working with a CSharp web-site (and am new to it). I have a
javascript function that accepts variables from my CSharp code. It all works
fine, with the exception of one variable type. I created an ArrayList
variable in my CSharp program and it collects the information i need with no
problem. I pass it to my javascript with no problem. Where I'm having a
problem is retreiving the ArrayList values once it's been passed to the
javascript. Since I am not familiar with CSharp and Javascript I am not sure
where to turn for help.

It appears to me that the ArrayLlist was successfully passed to my
javascript function without error, since the remainder of my javascript
works fine. But, when I try to retrieve anything from my array list I have no
luck.

So, If I had the function below, that was accepting an array list as such,
and the array list contains 4 items, how could I display the results in a
window. (My actually purpose is not to display in a window, but I just want
to get somethign working right now).

function CalcTotal(myArrayList)
(
for (i = 1; i < 5; i++)
{
window.alert('myArrayList Value: ' + i + ' - ' + myArrayList(i) );
}
}

My ulimate goal is to scan through the results of the ArrayList to perform
some calculations on a web-page. I've got this part working, but I need to
pass in my answers via an ArrayList.

Any help would be greatly appreciated.
You can't call a Javascript function directly from C#, as they don't
exist in the same place, and they don't exist at the same time.

To call a Javascript function from C# you would create Javascript code
that makes the call and put it in the page. As the page is sent as text
to the browser, you can only use data that can be represented as text
when you create the Javascript code that makes the call.

There is no ArrayList object in Javascript, so what you would use on the
client side is an array. An arrayList is a list of objects, and that can
not be represented as text as is, you would have to represent each item
in the list as text.

Unless you are stuck with framework 1.x, you shouldn't use ArrayList at
all. You should use a type safe list like List<string>, or if you
absolutely need to put object references in the list (which is rare as
you usually have some more specific type that the data has in common),
use List<object>.

--
Göran Andersson
_____
http://www.guffa.com
Aug 6 '08 #4

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

Similar topics

6
by: Stephen | last post by:
Im trying to carry work out an else if clause in the below method but i'm having a lot of difficulty getting the correct code which allows me to check and see if an arraylist items has text in it...
16
by: Cybertof | last post by:
Hi ! I'm wondering about the use of the 'using' statement. In a procedure, should i declare all instance variables in a using clause ? In the below code, what would happen if MyFont & MyFont2...
7
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a...
3
by: Bear | last post by:
Hello there How come it's possible to add values of the type "int" into an ArrayList when the Add member function only accepts values of type "object"? Is an int just a "typedef" of the Int32...
5
by: Matthias Kwiedor | last post by:
Hi! What i want to do, is to put an ArrayList into a Hashtable. So i can access the ArrayList fast over the key-indexing of the Hashtable. What i did is to put the ArrayList into the...
0
by: Just D. | last post by:
There is an interesting article - http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=542&printer=t It shows how to serialize the ArrayList of identical objects. I did it a year...
5
by: ZS | last post by:
Hi, Here is a piece of code where I have a class by name SomeClass array1 consists of objects of the type SomeClass array2 is intialized with contents of array1. Why does changes made to the...
22
by: Steven Blair | last post by:
I need to perform a Deep Copy on an ArrayList. I wrote a small sample app to prove this could be done: ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); a.Add("Hello"); b =...
3
by: djp | last post by:
Hi I have to sort arraylist. I tried to do this using this page as a reference: http://www.java2s.com/Code/CSharp/Collections-Data-Structure/UseIComparer.htm I did it exactly the same way but...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.