This is a migrated thread and some comments may be shown as answers.

Custom extender radnumerictextbox

2 Answers 94 Views
Input
This is a migrated thread and some comments may be shown as answers.
Frank Beerens
Top achievements
Rank 1
Frank Beerens asked on 05 Mar 2013, 03:48 PM
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
                    args.set_cancel(true);
                    //now fake a decimal seperator pressed keypress
                    sender._numPadDecimalSeparatorPressed = true;
                    //and send it back to the telerik handler
                    sender._onTextBoxKeyPressHandler(args._domEvent);                   
                }
            }

2 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 08 Mar 2013, 03:28 PM
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");
    }
</script>

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

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,
Vasil
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.
0
Frank Beerens
Top achievements
Rank 1
answered on 11 Mar 2013, 07:59 AM
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.

Cheers,



Tags
Input
Asked by
Frank Beerens
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Frank Beerens
Top achievements
Rank 1
Share this question
or