RegularExpressionValidator VS Ajax 1.0.20229

时间:2010-07-28 19:20:51

标签: asp.net vb.net asp.net-ajax reg-expressionvalidator

我们的网站.NET Framework 2.0Ajax version 10618一起运行。

但是,因为它是,这是一个旧版本的DLL,所以我们计划在它切换到它的“最新的”版本的.NET Framework 2.0,则AjaxControlToolkit version 20229

在我们的测试中,我们检测到ASP控件RegularExpressionValidator存在问题,该控件过去在旧版本中运行良好。

每当目标控件的输入与验证不匹配时,控件都会显示我的 文本,在此情况下是红色asterisc dispositioned一样,下一行中,并显示在控制如下:"-1.7976931348623157e+308"

那里有没有什么错的表达式,因为正如我所说,它正常工作与旧版本的Ajax,我无法找到与RegularExpressionValidatorsAjax版本的任何东西。

PS:验证器和控件都在UpdatePanel内。

PS 2:使用旧的版本,它将把0在控制和然后右显示我的红色asterisc它旁边当表达式将不匹配

修改

这是完全复制的控件:

<asp:RegularExpressionValidator ID="ValidateFooOrder" 
runat="server" ControlToValidate="txtFooNum"                                                    
Text="*" ErrorMessage="Invalid Foo number" 
ValidationExpression="^\d{0,4}$" ValidationGroup="GenerateFooFile" />

它附加了NumericUpAndDownExtender

<ajaxToolkit:NumericUpDownExtender ID="NumericExtenderFooNum" 
runat="server" TargetControlID="txtFooNum"                                                    
TargetButtonDownID="FooBack" TargetButtonUpID="FooForward" />

2 个答案:

答案 0 :(得分:2)

好的,我有同样的问题,这是我的发现:

首先是-1.7976931348623157E+308的来源。它等于Minimum AjaxControlToolkit.NumericUpDownBehavior属性,Sys.Application.add_init(function() { $create(AjaxControlToolkit.NumericUpDownBehavior, {"Maximum":1.7976931348623157E+308,"Minimum":-1.7976931348623157E+308, /* other non relevant stuff */); }); 属性在Sys.Application.init Event处理程序之一中调用:

Double

所以,这里没有魔法,只有Minimum的最小值。 readValue是与版本10618相比的新属性。

接下来,为什么在页面显示后立即显示?发生这种情况是因为在AjaxControlToolkit.NumericUpDownBehavior.prototype中定义的this._min函数内部Minimum(等于来自$create的{​​{1}}参数)的值被分配给输入,如果它是空的。 readValue来源:

readValue : function() {
        /// <summary>
        /// Parse value of textbox and this._currentValue to be that value.
        /// this._currentValue = this._min if some there is an exception
        /// when attempting to parse.
        /// Parse int or string element of RefValues
        /// </summary>

        if (this._elementTextBox) {
            var v = this._elementTextBox.value;
// The _currentValue of NumericUpDown is calculated here 
            // if textbox empty this._currentValue = this._min
            if(!this._refValuesValue) {
                if(!v) {
                    this._currentValue = this._min;
                } else {
                    try {
                        this._currentValue = parseFloat(v);
                    } catch(ex) {
                        this._currentValue = this._min;
                    }
                }
                if(isNaN(this._currentValue)) {
                    this._currentValue = this._min;
                }
// And assigned here. In case of empty input we will get -1.7976931348623157E+308 if Minimum was not changed
                this.setCurrentToTextBox(this._currentValue);
                this._valuePrecision = this._computePrecision(this._currentValue);
            } else {
                if(!v) {
                    this._currentValue = 0;
                } else {
                    var find = 0;
                    for (var i = 0; i < this._refValuesValue.length; i++) {
                        if (v.toLowerCase() == this._refValuesValue[i].toLowerCase()) {
                            find = i;
                        }
                    }
                    this._currentValue = find;
                }
                this.setCurrentToTextBox(this._refValuesValue[this._currentValue]);
            }
        }
    }

Minimum之前,在版本10618中,默认值为0。所以我认为可以通过在扩展器声明中明确指定Minimum值来解决所描述的问题:

<ajaxToolkit:NumericUpDownExtender ID="NumericExtenderFooNum" runat="server" 
     Minimum="0"
     TargetControlID="txtFooNum"
     TargetButtonDownID="FooBack" TargetButtonUpID

我发现的另一件事是change事件调度在IE的新版本中工作错误(为了使其工作,应该启用兼容性视图,但我认为这不是公共网站的选项)。

问题出在setCurrentToTextBox函数中。如果使用document.createEvent创建,event对象在处理程序(例如验证处理程序)中总是null。要解决此问题,应交换条件,以便使用createEventObject创建IE中的所有事件。

// Current implementation of version 20229
setCurrentToTextBox : function(value) {
            // full sources are not shown, only if matters here

            if (document.createEvent) {
                // event is created using createEvent
            } else if( document.createEventObject ) {
                // event is created using createEventObject 
            }
        }
    }

// Updated implementation
setCurrentToTextBox : function(value) {
            // full sources are not shown, only if matters here

            if (document.createEventObject) {
                // event is created using createEventObject 
            } else if(document.createEvent) {
                // event is created using createEvent
            }
        }
    }

答案 1 :(得分:-1)

查看错误消息,意味着正在测试的数字超出了表达式的边界。唯一允许的数字介于0到9999之间。不允许使用字母,标点符号或其他字符。表达式的另一部分断言数字周围的锚点,作为行或单词的开头和结尾。唯一允许的其他值是NULL,这可能是更新更严格并给出错误的地方。例如,如何验证不存在的数字或数字“\ d”(零字符)?