内容页面-会话值的javascript值 [英] Content page - javascript value to Session variable
问题描述
目前,我正在C.3.5中使用asp.net.
我正在使用母版页.
在这里,我需要捕获浏览器的本地时间,并希望在页面加载时将其存储在会话变量中.我正在使用以下javascript代码
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
<script language="javascript" type="text/javascript">
function GetClientUTC()
{
var now = new Date()
var offset = now.getTimezoneOffset()
document.getElementById('<%=hidTime.ClientID%>').value = offset
}
</script>
调用函数为:< body onload ="GetClientUTC()">
并在页面加载中按以下方式分配
calling function as : <body onload="GetClientUTC()">
and in page load i m assigning as following
Session["LocaltimeZone"]=hidTime.Value
但我无法获得价值,总是空虚.
请帮助我
-Karan
but i cannot get value and always showing empty.
kindly help me
-Karan
推荐答案
您要么需要通过AJAX回发将其发送,要么将其设置为cookie并在下一页请求中将其读出,或者执行所有在客户端进行处理,或者让用户在配置文件中设置其本地时区并在服务器端进行计算.
最简单的方法是在首页/登录页面上设置Cookie(有效期很短,即1天),然后读取该Cookie. (我认为JavaScript仍然可以编写发送回服务器的cookie.)
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.)
添加
runat='server'
属性的控件,您在上面的javascript代码中为其设置了值.
希望我能解决您的问题
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
这篇关于内容页面-会话值的javascript值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!