471,344 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 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 3682
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Stephen | last post: by
16 posts views Thread by Cybertof | last post: by
7 posts views Thread by Alex Ting | last post: by
3 posts views Thread by Bear | last post: by
5 posts views Thread by Matthias Kwiedor | last post: by
reply views Thread by Just D. | last post: by
5 posts views Thread by ZS | last post: by
22 posts views Thread by Steven Blair | last post: by
3 posts views Thread by djp | last post: by

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.