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#

1
  • 2
    C# and asp-classic? maybe asp.Net? Commented Apr 4, 2012 at 0:42

3 Answers 3

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>");
    }
Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

@shiplu.mokadd.im I answered this question from my cellphone. Makes it a bit hard to write sample code. I've edited the answer.
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/

2 Comments

The links I shared have plenty of code already. If you are too lazy to read them, I can't help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.