简体   繁体   中英

ASP.NET AJAX ToolKit: Numeric MaskedEditExtender issue

I have an AJAX ToolKit MaskedEditExtender control:

<asp:TextBox ID="payRateTextBox" runat="server" 
    CssClass="valueControl"></asp:TextBox>

<asp:MaskedEditExtender ID="payRateMaskedEditExtender" runat="server" 
    AcceptNegative="Left" InputDirection="RightToLeft" 
    Mask="999.99" MaskType="Number" 
    TargetControlID="payRateTextBox"  />

Empty text looks like the following when it gets focus:

__ _ _ . _ _

The problem is the extender dosent allow user to enter a 0 as the first entered character in the first digit at the left of the point (Where the X resides) ..

___ X. ___

Here is a demonstration.

Suggestions are apprectiated ..

This is a known issue. Unfortunately, it seems it doesn't have any solution yet.

Take a look at these links:

http://ajaxcontroltoolkit.codeplex.com/workitem/25108

ASP.NET MaskedEditExtender & TextBox: Cannot enter zero, workarounds? Solutions?

http://forums.asp.net/t/1087548.aspx

Try put this code in your page

<script type="text/javascript">
    Sys.Application.add_load(function () {
        Sys.Extended.UI.MaskedEditBehavior.prototype._MoveDecimalPos = 
           function () {
              var e = this.get_element();
              var wrapper = Sys.Extended.UI.TextBoxWrapper.get_Wrapper(e);
              var curpos = this._LogicFirstPos;
              var max = this._LogicLastPos;
              var posDc = -1;
              while (curpos < max) {
                 if (wrapper.get_Value().substring(curpos, curpos + 1) ==
                     this.get_CultureDecimalPlaceholder()) {
                    posDc = curpos + 1;
                    break;
                }
                curpos++;
            }
            if (posDc == -1) {
                return;
            }
            this.setSelectionRange(posDc, posDc);
        };
    });
</script>

I know I cant earn my own bounty, so, my answer here is just for suggesting a solution for the problem.

The problem can be solved simply by eliminating the assigning of the InputDirection property !! I guess it is not appropriate to use it while using float point anyway ..

Of course if I knew that at first place I would save a 50 reputations ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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