服务器端获取客户端信息(时间 etc..)
2010-10-19 16:43
260 查看
能在client端写JavaScript,就尽量在客户端写。
格式化时间:
代码
//Register clientjs and hiddenfield to get client time with format "yyyy/MM/dd hh:mm:ss"
private const string CLIENTTIME_SCRIPT_ID = "__CLIENTTIMEJS";
private const string CLIENTTIME_FIELD = "__CLIENTTIME";
private string ClientTime
{
get
{
return this.Request.Form[CLIENTTIME_FIELD];
}
}
protected override void OnLoad(EventArgs e)
{
ClientScript.RegisterHiddenField(CLIENTTIME_FIELD, "");
if (!ClientScript.IsOnSubmitStatementRegistered(typeof(string), CLIENTTIME_SCRIPT_ID))
{
ClientScript.RegisterOnSubmitStatement(typeof(string),
CLIENTTIME_SCRIPT_ID, "var today = new Date();var year =today.getFullYear();var month =today.getMonth()+1;" +
"var day = today.getDate();var hours=today.getHours();var minutes=today.getMinutes();var seconds=today.getSeconds();" +
"document.getElementById('" +
CLIENTTIME_FIELD + "').value=year+'/'+formatWithZero(month)+'/'+formatWithZero(day)+' '+formatWithZero(hours)+':'+formatWithZero(minutes)+':'+formatWithZero(seconds)");
}
base.OnLoad(e);
}
格式化时间:
代码
//Register clientjs and hiddenfield to get client time with format "yyyy/MM/dd hh:mm:ss"
private const string CLIENTTIME_SCRIPT_ID = "__CLIENTTIMEJS";
private const string CLIENTTIME_FIELD = "__CLIENTTIME";
private string ClientTime
{
get
{
return this.Request.Form[CLIENTTIME_FIELD];
}
}
protected override void OnLoad(EventArgs e)
{
ClientScript.RegisterHiddenField(CLIENTTIME_FIELD, "");
if (!ClientScript.IsOnSubmitStatementRegistered(typeof(string), CLIENTTIME_SCRIPT_ID))
{
ClientScript.RegisterOnSubmitStatement(typeof(string),
CLIENTTIME_SCRIPT_ID, "var today = new Date();var year =today.getFullYear();var month =today.getMonth()+1;" +
"var day = today.getDate();var hours=today.getHours();var minutes=today.getMinutes();var seconds=today.getSeconds();" +
"document.getElementById('" +
CLIENTTIME_FIELD + "').value=year+'/'+formatWithZero(month)+'/'+formatWithZero(day)+' '+formatWithZero(hours)+':'+formatWithZero(minutes)+':'+formatWithZero(seconds)");
}
base.OnLoad(e);
}
相关文章推荐
- ASP.NET获取客户端、服务器端的信息
- .NET获取客户端、服务器端的信息
- ASP.NET获取客户端、服务器端基础信息
- Unix网络编程卷一: 从服务器获取时间信息(三)-daytimetcpcli2客户端每次执行结果不同
- ASP.NET获取客户端、服务器端基础信息集合
- ASP.NET获取客户端、服务器端基础信息集合
- C#获取客户端及服务器端主机信息
- 获取客户端及服务器端信息
- 如何在服务器端获取丰富的客户端信息?
- 在客户端获取服务器端的时间
- Extjs练习——服务器端获取信息填充客户端表单,注意Radio以及Checkbox值的传递
- ASP.NET获取客户端、服务器端基础信息
- 织网的日子里——第一章:TCP时间获取之客户端和服务器端程序
- .NET获取客户端、服务器端基础信息
- 【转】C#获取客户端及服务器端主机信息及其获取IP地址
- ASP.NET----获取客户端浏览器信息,获取服务器端主机名和 IP
- 客户端实时获取Oracle数据库服务器端的系统时间
- .NET获取客户端、服务器端基础信息
- 织网的日子里——第一章:TCP时间获取之客户端和服务器端程序
- WCF实现将服务器端的错误信息返回到客户端