Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Dear All,

I have a requirement to store the javascript values into database. i.e., I am getting the values in the javascript method, so i want to store these values in to database, so i took hidden values, and assign javascript method return values to these hidden values and try to getting these values in code behind try to store in database. But hidden values are showing empty string. Please help me, have any idea about this issue.

Thanks in Advance.
Posted
Comments
Nandakishore G N 8-Dec-13 23:31pm    
paste the code what you have done till now..
Karthik_Mahalingam 9-Dec-13 1:18am    
post your code..
Maria Vinod 9-Dec-13 23:05pm    
<asp:HiddenField ID="hdn_Lat" runat="server" Value="0" />
<asp:TextBox ID="txtAddress" runat="server" /> <br />
<asp:Button ID="btnAdd" runat="server" Text ="Add Location"
OnClientClick="javascript:return GetLocation();" onclick="btnAdd_Click1" />
<asp:Label ID="Label1" runat="server">


Javascript method:

<script type="text/javascript">
<!--
function GetLocation() {
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("txtAddress").value;
var hdnLat = document.getElementById('<%= hdn_Lat.ClientID %>').value;
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();
hdnLat = latitude;
alert(hdnLat);
//alert("Latitude: " + latitude + "\nLongitude: " + longitude);
} else {
alert("Request failed.")
}
});
};
//-->
</script>


Code behind:

protected void btnAdd_Click1(object sender, EventArgs e)
{

//string value ;
//ClientScript.RegisterStartupScript(this.GetType(), "GetData", "a=GetLocation():alert(a)", true);

Label1.Text = hdn_Lat.Value;

}

 
Share this answer
 
Try like below...

In JavaScript,
JavaScript
document.getElementById('<%=HiddenFieldID.ClientID%>').value = "someValue";

In C# Code Behind,
C#
var hiddenFieldValue = HiddenFieldID.Value
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900