Calling a javascript function using an ASP.Net button control

Poppy-MarieJ

New Member
Here is my code:\[code\]<script type="text/javascript"> var geocoder; var map; var latlngstr; function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(-34.397, 150.644); var mapOptions = { zoom: 15, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); } function codeAddress() { var address = document.getElementById('address').value; geocoder.geocode({ 'address': address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { latlngstr = results[0].geometry.location; map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); } else { alert('Geocode was not successful for the following reason: ' + status); } }); document.getElementById('lat').value = http://stackoverflow.com/questions/15598950/latlngstr.lat(); document.getElementById('lng').value = http://stackoverflow.com/questions/15598950/latlngstr.lng(); } </script> </head> <body onload="initialize()"> <form id="form1" runat="server"> <div> <input id="address" type="text" value="http://stackoverflow.com/questions/15598950/sydney" /> <input type="button" value="http://stackoverflow.com/questions/15598950/Geocode" onclick="codeAddress()"> <input id="lat" type="text" /> <input id="lng" type="text" /> </div> <asp:Button ID="Button1" runat="server" Text="Button" EnableViewState="False" ViewStateMode="Disabled" OnClientClick="javascript:return codeAddress();"/> <div id="map-canvas"></div> </form> </body> </html>\[/code\]I want to call the function \[code\]codeAddress\[/code\]. When I call this function with an html button, the button with the value \[code\]Geocode\[/code\], it works fine. But when I call that function with an ASP.Net button the 'else' part is executed and it produces no result.
 
Back
Top