How to get an array in asp (Server side) to javascript?

Go To StackoverFlow.com

0

Hi i have float array in server side i want to take this array to javascript how do i do this?

I'm using c#

2012-04-04 00:34
by Guruparan
C# and asp-classic? maybe asp.Net - Alexei Levenkov 2012-04-04 00:42
asp.Net no asp classi - Guruparan 2012-04-04 01:12


1

Here is an example by registering the values using clientscript:

On your code behind:

protected void Page_Load(object sender, EventArgs e)
{
  foreach(var f in myFloats)
     Page.ClientScript.RegisterArrayDeclaration("myFloats", f.ToString());
}

You see a more complete example here:

http://www.codeproject.com/Articles/92600/How-to-pass-ASP-NET-server-side-array-to-client-si

Hope it helps.

2012-04-04 00:48
by Reinaldo
Read http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answer - Shiplu Mokaddim 2012-04-04 01:13
@shiplu.mokadd.im I answered this question from my cellphone. Makes it a bit hard to write sample code. I've edited the answer - Reinaldo 2012-04-04 02:10


3

As a simple exsample :

    protected void Page_Load(object sender, EventArgs e)
    {
        // Convert your float array to below 
        var list = new List<string>() { "'1.00'", "'2.00'", "'3.00'", "'4.00'" };
        Page.ClientScript.RegisterArrayDeclaration("arr ", string.Join("," , list.ToArray()));
        Page.ClientScript.RegisterStartupScript(this.GetType(), "excute", "<script language='javascript'>alert(arr);</script>");
    }
2012-04-04 01:13
by shenhengbin


0

http://blogs.microsoft.co.il/blogs/pini_dayan/archive/2009/03/12/convert-objects-to-json-in-c-using-javascriptserializer.aspx

then

http://api.jquery.com/jQuery.getJSON/

2012-04-04 00:42
by Nathan Rice
Could you show some code beside giving only link - Shiplu Mokaddim 2012-04-04 00:46
The links I shared have plenty of code already. If you are too lazy to read them, I can't help you - Nathan Rice 2012-04-04 00:59
read http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answer - Shiplu Mokaddim 2012-04-04 01:13