Server Error in ‘/InsusTutorials’ Application.
The value ‘5/15/2012’ of the MaximumValue property of ‘RangeValidator1’ cannot be converted to type ‘Date’.
Description: An unhandled
exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and
where it originated in the code.
Exception Details:System.Web.HttpException: The value ‘5/15/2012’ of the
MaximumValue property of ‘RangeValidator1’ cannot be converted to type
‘Date’.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
一点资讯,
Version Information:
Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
一位网友程序出现如上Error,他把程序发送过来,但是尚未数据库。Insus.NET只好拷贝程序关键部分做测试了。现在Insus.NET把它帖出来,方便遇上等同标题的人也足以做测试。
aspx:
View Code
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox><br />
<asp:RangeValidator ID=”RangeValidator1″ runat=”server” ErrorMessage=”请输入有效日期”
Type=”Date” ControlToValidate=”TextBox1″ CultureInvariantValues=”True” SetFocusOnError=”True” Width=”131px”></asp:RangeValidator>
.aspx.cs:
View Code
protected void Page_Load(object sender, EventArgs e)
{
this.RangeValidator1.MinimumValue = DateTime.Today.ToShortDateString();
this.RangeValidator1.MaximumValue = DateTime.Today.AddDays(365).ToShortDateString();
}
当您run这一个代码时,你会发现错误的出现。
难点出在BaseCompareValidator.CultureInvariantValues
属性上。更加多相关音信,可以参见Microsoft
msdn网站:http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.basecomparevalidator.cultureinvariantvalues.aspx
化解难点,把须要把CultureInvariantValues=”True”设为False或者是剔除。