日期比较不适用于IIS

编程入门 行业动态 更新时间:2024-10-08 08:30:29
本文介绍了日期比较不适用于IIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在txtDate文本框的文本更改事件上编写了以下代码。

I have written the following code on text change event of txtDate textbox.

DateTime dt1 = DateTime.Parse(txtVrDate.Text.Trim()).Date; DateTime dt2 = DateTime.Now.Date; if ((dt2 - dt1).Days > 2) { ScriptManager.RegisterStartupScript(this, typeof(string), "myalert", "alert('InValid Date');", true); txtDate.Text = DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("dd/MM/yyyy"); txtDate.Focus(); }

它在本地asp开发服务器上工作,但在IIS上发布时它不验证textbox。我无法弄清楚问题是什么。 请帮帮.... 提前感谢...

Its working on local asp development server but when published on IIS it does not validate textbox.I m not able to figure out whats the problem. Please help.... thanks in advance...

推荐答案

可能是用户输入或本地化问题:DateTime.Parse使用它运行的PC的区域设置 - 这将是您的PC用于开发,但将是用于生产的托管PC。在物理上运行IIS的计算机将确定它所设置的语言环境,以及它所期望的日期/时间格式 - 这可能与客户日期/时间格式不同。 最好的解决方案是不使用文本框进行日期输入:有一个Calendar控件(或各种类似的)可以做得更好,但它以客户端格式显示数据,并返回DateTime值直接到您的代码。 Probably, it either user input or a localization problem: DateTime.Parse uses the locale of the PC it is running on - which will be your PC for development, but will be the hosting PC for production. Where the computer running IIS is located physically will determine what locale it is set for, and thus what date/time format it expects - this may not be the same as the client date/time format. The best solution is to not use text boxes for date inputs: there is a Calendar control (or various similar) which does a better job, but which presents data in the client format, and returns a DateTime value directly to your code.

更多推荐

日期比较不适用于IIS

本文发布于:2023-11-27 11:09:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637823.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不适用于   日期   IIS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!