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 8053731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:56:47+00:00 2026-06-05T07:56:47+00:00

Before I explain my situation, please have a look at the very important notice!!

  • 0

Before I explain my situation, please have a look at the very important notice!!

1.My javascript is not embedded in .aspx file, so something like

    var strMessage = '<%= str%>';
    StartGeocoding(strMessage);

is not working (I tried a lot, but if you can improve it please let me know)

2.Also, I already used

    Page.ClientScript.RegisterStartupScript( , , , )

function, so I think I am not allowed to use twice.

================================================================

So, here
In “Location.js” (seperated from .aspx)

    function LoadMap(count) {       
        var asdf = (something variable from code-behind);
        var counts = count;                      
        myMap = new VEMap("mapDiv");
        myMap.LoadMap();
        StartGeocoding(asdf);    // it will show the map with location info of "asdf"
    }

In code behind, there is something

    public string blahblah = "1 Yonge Street"

Basically, I will get the address from code behind, and I will show it using javascript.
If you (my LORD!) can teach me how to get the variable in C# from javascript, that would be very appreciated!!!

If you guys wanna challenge, here is bonus(?) question

actually, I will show the multiple location in a map. Therefore, instead of having one string “blahblah”, I might have a list of string

    <list>Locationlist        //not array

So, ‘count’ in LoadMap() function will recognize how many entries I have. How to get each location information from javascript? is this possible? Any idea?

  • 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-06-05T07:56:48+00:00Added an answer on June 5, 2026 at 7:56 am

    Here’s what I had in mind.
    On code-behind, let’s say the Page_Load method, you can have the following code:

    List<string> locations = new List<string> { "1 Yonge Street", "100 Yonge Street", "123 Microsoft Way" };
    
    //transform the list of locations into a javascript array. 
    //The generated script should look like window.myLocations = ['1 Yonge Street', '100 Yonge Street', etc];
    StringBuilder script = new StringBuilder();
    script.Append("window.myLocations = [");
    foreach(string location in locations){
      if(script.Length > 0){
        script.Append(", ");
      }
      script.Append("'"+System.Web.HttpUtility.JavaScriptStringEncode(location) +"'");
    }
    script.Append("];");
    
    //then register this script via RegisterStartupScript.
    Page.ClientScript.RegisterStartupScript( this, this.GetType(), "registerMyLocations", script.ToString(), true);
    

    At this point you can acccess the registered array in Location.js:

    function LoadMap(/*count*/) {       
            var asdf = window.myLocations[0]; //this would be '1 Yonge Street' in your case
            alert(asdf);
            //var counts = count;
            var counts = window.myLocations.length;                      
            alert(counts);
    
            myMap = new VEMap("mapDiv");
            myMap.LoadMap();
            StartGeocoding(asdf);    // it will show the map with location info of "asdf"
        }
    

    Some remarks:

    • To use the StringBuilder class you need to add a “using System.Text” at the top of the file;

    • the System.Web.HttpUtility.JavaScriptStringEncode is needed to ensure that the serverside strings are correctly encoded (taken from Caveats Encoding a C# string to a Javascript string). It is available only in .Net 4, from what I understand.

    • if you have a ScriptManager on the page it is best to use the RegisterStartupScript on the ScriptManager rather then the method in the Page.ClientScript

    I cannot test the above code right now but you should get the basic ideea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me explain the situation before I ask the question. I have a site,
Before delving into the issue, first I will explain the situation. I have two
Before any one suggests HTML, I explain later why thats not an option here.
Before answering, it is not as easy question as you might have thought about
Before you say its a duplicate question, please let me explain (as I've read
I have the following situation. A customer uses JavaScript with jQuery to create a
I guess I have to set some context before I explain the problem I
This is difficult situation to explain. Have a service process that starts 2 threads,
Could you please explain me the reason of the following situation. Today I wrote
Firstly, I'll explain the situation I'm in with my applicaton before I get onto

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.