Custom extender radnumerictextbox

3 posts, 0 answers
  1. Frank Beerens
    Frank Beerens avatar
    26 posts
    Member since:
    Jan 2010

    Posted 05 Mar 2013 Link to this post

    Dear Telerik,

    i would like to use a custom ajax extender to use with the numeric textbox. Sadly i get a similiar error to this one:

    Extender control '' cannot extend 'myNumericTextbox1'. Extender controls of type 'CustomExtenders.MyCustomerExtender1' cannot extend controls of type 'Telerik.Web.UI.RadNumericTextBox'.

    Am i doing something wrong or is this by design?

    This because for numeric textboxes we want to allow 2 decimal seperators, both , and .
    We have a solution, namely: see code.

    Basicly we handle a '.' keypress differently. In that case we cancel the current keypress and simulate another one
    which we call on the numerictextbox. Cause we set the property _numPadDecimalSeparatorPressed to true,
    we can reuse the current event without problems :).

    We would like to solve this in an extender, please advice.
    function keypress(sender, args) {
                    var char = args.get_keyCharacter();
                    //allow a dot to be a comma (only needed when we DONT press numpad decimalseperator)
                    if (char == "." && !sender._numPadDecimalSeparatorPressed) {
                        //cancel current event
                        //now fake a decimal seperator pressed keypress
                        sender._numPadDecimalSeparatorPressed = true;
                        //and send it back to the telerik handler

  2. Vasil
    Vasil avatar
    1635 posts

    Posted 08 Mar 2013 Link to this post

    Hello Frank,

    The Ajax Toolkit's extenders are designed to be used with normal asp:TextBox, and can not be applied to RadInput controls.

    You could override the designed behaviour, by overriding the _compileRegEx of RadNumericTextBox to allow both dot and comma as separator using this code:

    <asp:ScriptManager runat="server"></asp:ScriptManager>
    <script type="text/javascript">
        Telerik.Web.UI.RadNumericTextBox.prototype._compileRegEx = function ()
            this._acceptRegExp = new RegExp("[0-9\\.,]{1}");
            this._rejectRegExp = new RegExp("[^0-9,\\." + this.get_numberFormat().NegativeSign + "]{1}", "g");
            this._decimalReplaceRegExp = new RegExp("[,\\.]", "g");

    But make sure to change the GroupSeparator as well, for example set it as space:
    <telerik:RadNumericTextBox runat="server"
        NumberFormat-GroupSeparator=" ">

    Please note that this not supported solution by the design of the control. I have tested it in some scenarios and it works fine, however you should perform fully testing yourself before using it in real live project.

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Frank Beerens
    Frank Beerens avatar
    26 posts
    Member since:
    Jan 2010

    Posted 11 Mar 2013 Link to this post

    Hi Vasil,

    thanks for your feedback. I'll give it a go once we will need a custom keypress method. For now our solution works fine for our scenarios, but once we will need more keypress functionality it will get a bit messy and hard to maintain.


Back to Top