Click here to Skip to main content
15,849,054 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
currently i m using with C# 3.5.
i m using master page.
here i need to capture the browser local time and want to store in session variable in page load. i m using following javascript code
<script language="javascript" type="text/javascript">
            function GetClientUTC()
                var now = new Date()
                var offset = now.getTimezoneOffset()
                document.getElementById('<%=hidTime.ClientID%>').value = offset

calling function as : <body onload="GetClientUTC()">
and in page load i m assigning as following


but i cannot get value and always showing empty.

kindly help me


You either need to send it via an AJAX postback, or set it in a cookie and read that out in the next page request, or do all the processing with it client side, or have the user set their home time zone in a profile and calculate it on the server side.

The easiest way is to set a cookie (with a fairly short i.e. 1 day expiry) on the home/login page and read that. (I think JavaScript can write cookies that are sent back to the server, anyway.)
Share this answer
attribute to the control whose value you are setting in the javascript code above.

I hope I was able to solve your problem

Watch my first article posted on codeproject and comment and vote:
Drop me a mail for any comments, suggestions or questions.
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