查找浏览器当地时间ASP.NET [英] Finding browser local time in ASP.NET

查看:130
本文介绍了查找浏览器当地时间ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何找出用户在浏览您的网站在ASP.NET的本地时间?

How do you find out the local time of the user browsing your website in ASP.NET?

推荐答案

创建一个隐藏的输入控件来获取值回下页发的服务器。这将需要与在JavaScript中创建一个新的Date对象的值的页面onload事件来填充它。您将要创建一个JavaScript函数来做到这一点,使用的RegisterClientScriptBlock添加到页面。

Create a hidden input control to get the value back at the server on the next page postback. It will need to be populated it in the onload event for the page with the value of a new Date object created in JavaScript. You will want to create a JavaScript function to do this and add that to the page using RegisterClientScriptBlock.

像这样的东西;

function setNow(hiddenInputId)
{
     var now = new Date();
     var input = document.getElementById(hiddenInputId);

     if(input) input.value = now.toString();
}

然后创建路过隐藏的输入的客户端Id,然后函数的调用那块脚本添加到使用的RegisterStartupScript的页面,以便它运行在页面加载。

Then create a call to the function passing the ClientId of the hidden input and then add that piece of script to the page using RegisterStartupScript so that it runs on page load.

这篇关于查找浏览器当地时间ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆