Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hey Guys,
 
This is my javascript code:
 
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 21-Mar-13 2:37am
Comments
ryanb31 at 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 at 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.
ryanb31 at 21-Mar-13 8:10am
   
You can still do that in JS.
Abhinav_007 at 21-Mar-13 8:11am
   
can you please show that with an example.
It would be really helpful.
ryanb31 at 21-Mar-13 8:15am
   
Which part are you stuck on? You just need to get a value from a radio button list?
Abhinav_007 at 21-Mar-13 8:21am
   
Yes sir. In the first place i'm not able to call this function using a an asp radio button in a switch case. Meaning I simply don't know how to do that.
ryanb31 at 21-Mar-13 8:25am
   
"i'm not able to call this function using a an asp radio button in a switch case. " What does this mean? Are you wanting to call the function when the radio button is clicked or are you saying you want to check which radio button is selected in the function?
 
If you would use jquery it will make this much easier. For example, to get the value of a radiobutton list in jquery you do $('#RadioButtonList1 input:checked').val()
Abhinav_007 at 21-Mar-13 8:29am
   
Sir, actually i'll be inputting source, destination and the timezone(asp radio button) and as soon as i click get direction button(asp button), It shoud show me the output.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
declare string variable. and make that function as string and assign that string value in that variable.
 
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);
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 21 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100