Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hey Guys,

This is my javascript code:

C#
function calcRouteA() {

      var start = document.getElementById('DropDownList1').value;
      var end = document.getElementById('DropDownList2').value;
      var request = {
          origin: start,
          destination: end,
          provideRouteAlternatives: true,
          unitSystem: google.maps.UnitSystem.METRIC,
          travelMode: google.maps.DirectionsTravelMode.TRANSIT,
          transitOptions: {
          departureTime: new Date(1362568344000)
          }



      };
      directionsService.route(request, function (response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
              directionsDisplay.setDirections(response);
          }
                  });

              }



is it possible that I can write this function in the aspx.cs page?
Please reply asap.
Posted
Comments
ZurdoDev 21-Mar-13 7:49am    
Why do you want it in C#? Javascript executes on the client and C# executes on the server. You'll have to read the Google api documentation to find out though.
Abhinav_007 21-Mar-13 7:59am    
I want to add a switch case which will take input from asp radio button list which will take this javascript function and give output depending on the different departure time mentioned.
Currently the timestamp mentioned is for morning 9:00 am.
ZurdoDev 21-Mar-13 8:10am    
You can still do that in JS.
Abhinav_007 21-Mar-13 8:11am    
can you please show that with an example.
It would be really helpful.
ZurdoDev 21-Mar-13 8:15am    
Which part are you stuck on? You just need to get a value from a radio button list?

1 solution

Hi,

declare string variable. and make that function as string and assign that string value in that variable.

C#
string jsFn = "function calcRouteA() {var start = document.getElementById('DropDownList1').value; var end = document.getElementById('DropDownList2').value;"
      + "var request = {          origin: start,          destination: end,          provideRouteAlternatives: true,          unitSystem: google.maps.UnitSystem.METRIC,"
          + "travelMode: google.maps.DirectionsTravelMode.TRANSIT,          transitOptions: {          departureTime: new Date(1362568344000)          }  };"
            + "directionsService.route(request, function (response, status) {          if (status == google.maps.DirectionsStatus.OK) {              directionsDisplay.setDirections(response);          }"
            + "                  });}";



call that function like below...

ddl1.Attributes.Add("onselect", jsFn);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900