Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
hi,
currently i m using asp.net 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
XML
<script language="javascript" type="text/javascript">
            function GetClientUTC()
            {
                var now = new Date()
                var offset = now.getTimezoneOffset()
                document.getElementById('<%=hidTime.ClientID%>').value = offset
            }
        </script>

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

C#
Session["LocaltimeZone"]=hidTime.Value


but i cannot get value and always showing empty.

kindly help me

-Karan
Posted

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
 
Add
C#
runat='server'
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:
http://www.codeproject.com/KB/HTML/speechinputapi.aspx
or http://blog.robinrizvi.info
 
Drop me a mail for any comments, suggestions or questions.
mail@robinrizvi.info
 
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