locked
C# JavaScript RRS feed

  • Question

  • Can someone help me with this code from my aspx page. I want to get the value of "distance" to the C# code page behind and cannot seem to get it to work.

             function directionsUpdated(e) {
                 //Get the current route index.
                 var routeIdx = directionsManager.getRequestOptions().routeIndex;

                 //Get the distance units used to calculate the route.
                 //var routeOptx = directionsManager.getRequestOptions().routeOptimization;
                 directionsManager.setRequestOptions({
                     routeMode: Microsoft.Maps.Directions.RouteMode.driving,
                     routeOptimization: Microsoft.Maps.Directions.RouteOptimization.shortestDistance

                 });


                 //Get the distance of the route, rounded to 2 decimal places.
                 var distance = Math.round(e.routeSummary[routeIdx].distance * 100) / 100;

                 //Get the distance units used to calculate the route.
                 var units = directionsManager.getRequestOptions().distanceUnit;
                 var distanceUnits = '';

                 if (units == Microsoft.Maps.Directions.DistanceUnit.km) {
                     distanceUnits = 'km'
                 } else {
                     //Must be in miles
                     distanceUnits = 'miles'
                 }

                 //Time is in seconds, convert to minutes and round off.
                 var time = Math.round(e.routeSummary[routeIdx].timeWithTraffic / 60);

                 document.getElementById('routeInfoPanel').innerHTML = 'Distance: ' + distance + ' ' + distanceUnits + '<br/>Time with Traffic: ' + time + ' minutes';
      


             }


    • Edited by rlawrimore Wednesday, May 6, 2020 5:35 PM
    • Moved by CoolDadTx Thursday, May 7, 2020 2:23 PM ASP.NET related
    Wednesday, May 6, 2020 5:34 PM

All replies

  • Hello,

    You should ask here https://forums.asp.net/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, May 6, 2020 5:50 PM
  • Your JavaScript executes in the browser; the client's computer. Your C# executes in the server; a totally different computer. Your JavaScript needs to do something to cause the C# code to execute; use Karen's advice to ask about that.


    Sam Hobbs
    SimpleSamples.Info

    Wednesday, May 6, 2020 9:34 PM