Vineet
Vineet

Reputation: 12

asp.net capture client side time and insert it in DB

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 ..

Upvotes: 0

Views: 256

Answers (2)

cdonner
cdonner

Reputation: 37668

Are you are using the server-side id for HiddenField1, which will not work client-side? Check the HTML in your browser, or debug your Javascript to see if getElementById() returns a valid element.

Upvotes: 0

Sidharth Mudgal
Sidharth Mudgal

Reputation: 4264

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.

Upvotes: 1

Related Questions