Page.ClientScript.RegisterArrayDeclaration

G

Guest

Hi,
I have a 3 dimenionsal array which I populate in my C# code.

I then want to make this available to my Javascript so I do below.

Page.ClientScript.RegisterArrayDeclaration("myArray", myArray.ToString())

When I view my source html I see var myArray = new Array(System.Int32[,])

What am I doing wrong here?
 
B

bruce barker

the RegisterArrayDeclaration is rather stupid and useless. it takes two
parameters, the array name and a string which is the actual javascript
array initialization code. for an int array it wants:


Page.ClientScript.RegisterArrayDeclaration("myArray","1,2,3");

so you need a helper routine for an int array (air code):

public string JScriptArrayDeclaration(int[] a)
{
string s = "";
string sep = "";
for (int i=0; i < a.Length; ++i)
{
s += sep + a.ToString();
sep = ",";
}
return s;
}

-- bruce (sqlwork.com)
 
G

Guest

Thanks Bruce.

bruce barker said:
the RegisterArrayDeclaration is rather stupid and useless. it takes two
parameters, the array name and a string which is the actual javascript
array initialization code. for an int array it wants:


Page.ClientScript.RegisterArrayDeclaration("myArray","1,2,3");

so you need a helper routine for an int array (air code):

public string JScriptArrayDeclaration(int[] a)
{
string s = "";
string sep = "";
for (int i=0; i < a.Length; ++i)
{
s += sep + a.ToString();
sep = ",";
}
return s;
}

-- bruce (sqlwork.com)
Hi,
I have a 3 dimenionsal array which I populate in my C# code.

I then want to make this available to my Javascript so I do below.

Page.ClientScript.RegisterArrayDeclaration("myArray", myArray.ToString())

When I view my source html I see var myArray = new Array(System.Int32[,])

What am I doing wrong here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top