In my asp.net web application I need to capture the Client time and store it in a DB.For this I have written the follwing script in the head of my master:
{
function checkClientTimeZone() {
// Set the client time zone
var dt = new Date();
alert(dt.toTimeString());
document.getElementById("HiddenField1").value = dt.toTimeString();
}
window.onload = checkClientTimeZone;
</script>
}
Where the hidden field has been declared on the master page
On every page load the script runs well and alerts the time of the client . But when I refer the value of the hidden fild in the content page it stills reflects ‘Hi’ which is the default value. Could someone please help ..
I think you forgot to check if the page load is due to a postback. You should add the following check in your Page_Load function:
if (Page.IsPostBack)and then get the value in the hidden field and add it to the db.