14

We have a website that runs .NET Framework 2.0 with Ajax version 10618.

But as it is, that is an old version of the dll, so we planned on switching it to the "newest" version of it for the .NET Framework 2.0, the AjaxControlToolkit version 20229.

On our tests, we detected a problem with the ASP control RegularExpressionValidator, which used to work fine with the old version.

Whenever the input to the target control doesn't match the validation, the control displays my text, which in this case is a red asterisc dispositioned, like, in the next row, and it displays the following in the control: "-1.7976931348623157e+308".

Theres nothing wrong with the expression because as I said, it works fine with the older version of Ajax, and I couldn't find anything related to RegularExpressionValidators and Ajax versions.

PS: Both the validator and the control are inside an UpdatePanel.

PS 2: With the older version, it would put a 0 in the control and then show me the red asterisc right beside it when the expression wouldn't match.

Edit:

Here's the control, fully copied:

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

And it also has a NumericUpAndDownExtender attached to it:

<ajaxToolkit:NumericUpDownExtender ID="NumericExtenderFooNum" 
runat="server" TargetControlID="txtFooNum"                                                    
TargetButtonDownID="FooBack" TargetButtonUpID="FooForward" />
captainsac
  • 2,484
  • 3
  • 27
  • 48
Smur
  • 3,075
  • 7
  • 28
  • 46
  • I know this is an old question, but if you are still having issues: Can you post your designer code? It would be interesting to look it over and see if this is a change in how the regex is handled by the control or how the javacript is written. – Peter Jan 05 '11 at 20:24
  • @Patricker Ok, added the code. Sorry it took long. – Smur Jan 20 '11 at 19:41
  • I'm assuming that the issue is still happening since you updated your question, right? – Peter Jan 20 '11 at 19:48
  • @Patricker Yes it still happening. After taking into account what little things we'd have to fix by switching the Ajax Version, we ended up not updating it at all. – Smur Jan 21 '11 at 11:45
  • I removed the [ajax] and [regex] tags as this question doesn't really have anything to do with ajax or regex (it's specific to the implementation of a specific vendor's control) – JDB Jan 17 '13 at 16:14
  • @Cyborgx37 It's specific to a vendor's control. That's all about ajax and regex. Those are Ajax's Toolkit controls, and one of them uses a regex. I'd keep those two tags. – Smur Jan 18 '13 at 09:56
  • @FelipeFiali Yes, the control uses Ajax and Regex, but this question is not about how to use ajax or regex - it's about how to get a control working: "Theres nothing wrong with the expression". The OP doesn't even mention ajax (beyond the toolkit name). – JDB Jan 18 '13 at 14:23
  • 1
    @Cyborgx37 Oh and I wrote something wrong on the other comment. I meant that its _not_ specific to a vendor's control. I'll just add the ajaxtoolkit tag then. – Smur Jan 18 '13 at 15:16
  • some times the handlers are configured to support specific version.You might wanna add and extended version of script handler to make ajax compatible to your visual studio version – Sunny Gill Feb 10 '13 at 09:31

2 Answers2

2

Ok, I've got the same issue and here are my findings:

First is the source of -1.7976931348623157E+308. It is equal to the Minimum property of AjaxControlToolkit.NumericUpDownBehavior which is called in one of the Sys.Application.init Event handlers:

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

So, no magic here, just a minimum value of Double. Minimum is the new property comparing to version 10618.

Next, why it is showed as soon as page is displayed? This happens because inside readValue function which is defined in AjaxControlToolkit.NumericUpDownBehavior.prototype a value this._min(which is equal to Minimum parameter from $create) is assigned to input if it is empty. readValue sources:

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]);
            }
        }
    }

Before Minimum, in version 10618, default value was 0. So I think described issue could be solved by specifying Minimum value explicitly in extender declaration:

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

Another thing that I have found is that change event dispatching works wrong in new versions of IE (to make it work a Compatibility View should be enabled but I think this is not an option for public web sites).

The issue is in setCurrentToTextBox function. event object is always null in handlers (validation handlers for example) if created using document.createEvent. To fix this issue, condition should be swapped, so all events in IE will be created using createEventObject.

// 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
            }
        }
    }
Alexander Manekovskiy
  • 3,185
  • 1
  • 25
  • 34
-1

Looking at the error message, implies the number being tested is outside the boundaries of the expression. The only allowed numbers are between 0 and 9999. No letters, punctuation, or other characters are allowed. The other part of the expression asserts anchors around the number, either as beginning and end of a line or word. The only other allowed value is NULL, which is probably where the update is being more strict and giving the error. For example, how do you validate a number or digit "\d" that does not exist (zero characters)?

Daniel Liston
  • 230
  • 1
  • 10
  • My assumption (are these allowed?) is that most newer versions of anything fix bugs. Having a validation defined as a number, yet allowing that value to be NULL is a bug. The correct regular expression to validate a 1 to 4 digit number is "^\d{1,4}$" not 0,4. – Daniel Liston Apr 09 '13 at 00:01
  • Is that -1 because I did not agree with something? My answer was directed at the regular expression being wrong, which is wrong in any language, not just AJAX. The -1 is not justified and is unwarranted. – Daniel Liston Aug 14 '13 at 03:36
  • Your answer was speculation and doesn't even address the question of why an AJAX upgrade would change a legacy ASP.NET control. – John Saunders Aug 14 '13 at 04:47