I have a LinkButton in aspx page where on OnClientClick I am updating the value of Hidden Field, and on OnClick I am saving that value to the database.
<asp:LinkButton runat="server" ID="lnkUpdateGeocode" Text="Update Geocode"
OnClientClick="updateGeoCode()" OnClick="lnkUpdateGeocode_Click" />
where my updateGeoCode() function is
function updateGeoCode() {
var address = document.getElementById('lblDisplayAddress');
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
longitudeField = $get('<%=Longitude.ClientID %>');
latitudeField = $get('<%=Latitude.ClientID %>');
longitudeField.value = longitude;
latitudeField.value = latitude;
} else {
alert('Geocode was not successful');
}
});
};
and my lnkUpdateGeocode_Click() is
latitude = Latitude.Value.IsBlankOrNull() ? 0M : Convert.ToDecimal(Latitude.Value);
longitude = Longitude.Value.IsBlankOrNull() ? 0M : Convert.ToDecimal(Longitude.Value);
But I am always getting latitude and longitude values as 0.
So My Question is how to get the updated value of HiddenField in CodeBehind when I am changing that in javascript. Any help would be appreciated.
Update:
My HiddenField Value is set as runat="server"
<asp:HiddenField ID="Longitude" runat="server" EnableViewState="false" />
<asp:HiddenField ID="Latitude" runat="server" EnableViewState="false" />
I tried Request.Form[Latitude.UniqueID]
but it is also giving Blank string.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…