how to get Javascript varaible value in C#
<p>I have two Lat/long tables, 1000 rows each table. I wanted to calculate the distance between two latitude/longitude using Google Map API and store distance in DB.
The code is working fine but the catch is how to return calculated distance from javascript. I tried hidden field to store the distance since I have written below code in page load its not working..</p>

<pre><code>        SqlConnection sql_con = new SqlConnection("Database=myDB;Server=mySever;User Id=myID;password=PWD");
        SqlCommand sql_cmd = new SqlCommand("select Zip,Latitude,Longitude from ZipCodes", sql_con);
        SqlDataAdapter sql_adt = new SqlDataAdapter(sql_cmd);
        DataSet dsZip = new DataSet();
        sql_adt.Fill(dsZip);

        sql_cmd = new SqlCommand("select * from MyPlaceLatLong", sql_con);
        sql_adt = new SqlDataAdapter(sql_cmd);
        DataSet dsStore = new DataSet();
        sql_adt.Fill(dsStore);

        for (int zcnt = 0; zcnt &lt; dsZip.Tables[0].Rows.Count; zcnt++)
        {
            for (int i = 0; i &lt; dsStore.Tables[0].Rows.Count; i++)
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScssript", "&lt;script&gt;" +
                 "var origin1 = new google.maps.LatLng("+dsZip.Tables[0].Rows[zcnt]["Latitude"].ToString()+","+ dsZip.Tables[0].Rows[zcnt]["Longitude"].ToString()+");" +
                 "var origin2 = new google.maps.LatLng(" + dsStore.Tables[0].Rows[i]["lat"].ToString() + "," + dsStore.Tables[0].Rows[i]["long"].ToString() + ");" +
                  //"var origin1 = new google.maps.LatLng(55.930385, -3.118425);" +
                  //"var origin2 = new google.maps.LatLng(51.483061, -0.004151);" +
                 "var service = new google.maps.DistanceMatrixService();" +
                 " alert('Made it to calculateDistances');" +
                 "service.getDistanceMatrix(" +
                 "{" +
                   "origins: [origin1]," +
                   "destinations: [origin2]," +
                   "travelMode: google.maps.TravelMode.DRIVING," +
                   "unitSystem: google.maps.UnitSystem.IMPERIAL," +
                   "avoidHighways: false," +
                   "avoidTolls: false" +
                 "}, callback);" +
                 "function callback(response, status)" +
                   "{" +
                    "if (status == google.maps.DistanceMatrixStatus.OK) { " +
                    "var origins = response.originAddresses;   " +
                    "var destinations = response.destinationAddresses;" +
                    "for (var i = 0; i &lt; origins.length; i++) {" +
                    "var results = response.rows[i].elements;" +
                    "for (var j = 0; j &lt; results.length; j++) {" +
                    "var element = results[j];" +
                    "var distance = element.distance.text;" +
                    "var duration = element.duration.text; " +
                    "var from = origins[i];" +
                    "var to = destinations[j];" +
                   "alert('The distance:'+ distance);" +
                    "}}}}" +
               "&lt;/script&gt;");



            }
        }
</code></pre>
