Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7697725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:04:47+00:00 2026-05-31T22:04:47+00:00

I am building two arrays in c# and pass them to a js function

  • 0

I am building two arrays in c# and pass them to a js function like this:

            //call js to show the map with the markers
        string[] lats = new string[10];
        string[] longs = new string[10];

        for (int i = 0; i < 10; i++)
        {
            lats[i] = dv[i]["Latitude"].ToString();
        }

        for (int i = 0; i < 10; i++)
        {
            longs[i] = dv[i]["Longitude"].ToString();
        }

        StringBuilder sbLats = new StringBuilder();
        string[] latsArray = lats.ToArray<string>();

        //Build the JS array.
        sbLats.Append("[");
        for (int i = 0; i < latsArray.Length; i++)
        {
            sbLats.AppendFormat("'{0}', ", latsArray[i]);

        }
        sbLats.Append("]");

        StringBuilder sbLongs = new StringBuilder();
        string[] longsArray = longs.ToArray<string>();

        //Build the JS array.
        sbLongs.Append("[");
        for (int i = 0; i < longs.Length; i++)
        {
            sbLongs.AppendFormat("'{0}', ", longsArray[i]);

        }
        sbLongs.Append("]");


        ScriptManager.RegisterStartupScript(this, this.GetType(), "mapMarket", "buildMapWithMarkers('map_market', " + latsArray + ", " + longsArray + ", " + "false" + ");", true);

For some unknown reason this throws an exception here (in the aspx page, part of generated js):

buildMapWithMarkers('map_market', System.String[], System.String[], false)

which says:

Uncaught SyntaxError: Unexpected token ]

Can you please tell me where I am wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:04:48+00:00Added an answer on May 31, 2026 at 10:04 pm

    Solved it using @Skilwz suggestion (JavaScriptSerializer):

     //call js to show the map with the markers
            string[] lats = new string[10];
            string[] longs = new string[10];
    
            for (int i = 0; i < 10; i++)
            {
                lats[i] = dv[i]["Latitude"].ToString();
            }
    
            for (int i = 0; i < 10; i++)
            {
                longs[i] = dv[i]["Longitude"].ToString();
            }
    
    
            string serializedLat = (new JavaScriptSerializer()).Serialize(lats);
            string serializedLong = (new JavaScriptSerializer()).Serialize(longs);
    
            ScriptManager.RegisterStartupScript(this, this.GetType(), "mapMarket", "buildMapWithMarkers('map_market', " + serializedLat + ", " + serializedLong + ", " + "false" + ");", true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a range between two numbers (floats) and I'd like this range to
Hi I'm new to R and i'm building off of two guides from the
I have an NSArray that contains two types of objects. Lets call them Apple
I am building an array based off comparing two other arrays. But when I
I am building an app that needs to have support for two dimensional arrays
I have two excel files. The first excel file is like this: 12 A
I have two manifests that I swap round when building different releases of my
In .NET there are two version numbers available when building a project, File Version
I am building an content serving application composing of a cluster of two types
I'm building a utility application that synchronizes files across two systems for Mac OSX.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.