View Full Version : How to pass values from a Javascript to ASP.Net Texbox.

May 17th, 2013, 08:18 AM
Hi All,

I am trying to get GeoCodes from Google Maps ussing google map Javascript API.
I am able to get the same. But do not know how to pass it on to ASP.Net Textbox with name "txtLatLng".

Below is the code. Requesting you to guide me on the same.

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script language="javascript" type="text/javascript">

var map;
var geocoder;
function InitializeMap() {

var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions =
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
map = new google.maps.Map(document.getElementById("map"), myOptions);

function FindLocaiton() {
geocoder = new google.maps.Geocoder();

var address = document.getElementById('<%= txtAddressInput.ClientID %>').value;
//var LatLngCode = document.getElementById("<%:txtLatLng.ClientID %>").value;

geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location


var infowindow = new google.maps.InfoWindow({
content: 'Location info: <br/>Country Name:<br/>LatLng: ' + results[0].geometry.location
google.maps.event.addListener(marker, 'click', function () {
// Calling the open method of the infoWindow
infowindow.open(map, marker);
else {
alert("Geocode was not successful for the following reason: " + status);


function btnGeoCode_onclick() {
//alert("Script Not Yet Developed");


window.onload = InitializeMap;


Requesting guidance.

Old Pedant
May 17th, 2013, 08:27 PM
Same way you got the address. only in reverse:

document.getElementById("<%= txtLatLng.ClientID %>").value
= results[0].geometry.location.toString();