繁体   English   中英

RegularExpressionValidator VS Ajax 1.0.20229

[英]RegularExpressionValidator VS Ajax 1.0.20229

我们有一个运行.NET Framework 2.0Ajax version 10618

但实际上,它是dll的旧版本,因此我们计划将其切换为.NET Framework 2.0的“最新”版本,即AjaxControlToolkit version 20229

在我们的测试中,我们检测到ASP控件RegularExpressionValidator的问题,该控件过去可以在旧版本上正常工作。

只要目标控件的输入与验证不匹配,控件就会在下一行中显示我的文本(在本例中为红色星号),并在控件中显示以下内容: "-1.7976931348623157e+308"

表达式没有任何问题,因为正如我所说,它与较旧版本的Ajax ,并且我找不到与RegularExpressionValidatorsAjax版本有关的任何内容。

PS:验证程序和控件都在UpdatePanel中。

PS 2:使用旧版本时,它将在控件中放入0,然后在表达式不匹配时在其旁边显示红色星号。

编辑:

这是完全复制的控件:

<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" />

好的,我遇到了同样的问题,这是我的发现:

首先是-1.7976931348623157E+308的来源。 它等于AjaxControlToolkit.NumericUpDownBehaviorMinimum属性,该属性在Sys.Application.init事件处理程序之一中调用:

Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.NumericUpDownBehavior, {"Maximum":1.7976931348623157E+308,"Minimum":-1.7976931348623157E+308, /* other non relevant stuff */);
});

因此,这里没有魔术,只有Double的最小值。 Minimum是与10618版本相比的新属性。

接下来,为什么在页面显示后立即显示? 发生这种情况是因为在AjaxControlToolkit.NumericUpDownBehavior.prototype定义的readValue函数内部,将this._min (等于$create Minimum参数)值分配给输入(如果为空)。 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
            }
        }
    }

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM