0

I have a variable "place", which is changing dynamically (get diffrent values for some actions). Here JS code.

google.maps.event.addListener(autocomplete, 'place_changed', function () {
  var place = autocomplete.getPlace();
});

How to get this variable to asp.net(C#) in code behind?

1 Answer 1

1
document.getElementById('myHiddenField').value = place;

Just keep in mind that client IDs are dynamic in ASP.NET, unless you're using ASP.NET 4 and set ClientIDMode = "Static" on that hidden field. So you may need to add something like this to your Page_Load:

Page.RegisterStartupScript(this, "hiddenFieldIdSetter", "var hiddenFieldID = '"+ myHiddenField.ID +"';", true);

and then use the following javascript, instead:

document.getElementById(hiddenFieldID).value = place;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.