zoukankan      html  css  js  c++  java
  • The value '5/15/2012' of the MaximumValue property of 'RangeValidator1' cannot be converted to type 'Date'.

     

    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:

    [HttpException (0x80004005): The value '5/15/2012' of the MaximumValue property of 'RangeValidator1' cannot be converted to type 'Date'.]
       System.Web.UI.WebControls.RangeValidator.ValidateValues() +1324866
       System.Web.UI.WebControls.RangeValidator.ControlPropertiesValid() +12
       System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +36
       System.Web.UI.Control.PreRenderRecursiveInternal() +103
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
    

    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或者是删除。

  • 相关阅读:
    We7 2.7版:全拖拽建站 开源CMS
    We7 CMS 2.6RC2版本发布 开源CMS
    LINQ简易教程
    C# 引用 C# DLL
    ASP.NET中母版页与JavaScript控制的一点小问题
    LINQ连接远端数据库问题
    ASP.NET中自动生成XML文件并通过XSLT显示在网页中的方法
    【转载】常见逻辑错误
    因为压力大变得很郁闷的时候怎么办
    代码覆盖度C#代码监控工具NCover、Rational PureCoverage、BullseyeCoverage
  • 原文地址:https://www.cnblogs.com/insus/p/2047806.html
Copyright © 2011-2022 走看看