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

Display "Disabled" when the value of RadNumericTextBox is 0

6 Answers 239 Views
Input
This is a migrated thread and some comments may be shown as answers.
Rui
Top achievements
Rank 1
Rui asked on 08 Jun 2016, 07:32 AM

Hello,

     I have a RadNumericTextBox used to accept a numeric value. Now I  got a requirement that when the user input 0, the text in the text box should be changed to a string like "Disabled" instead of the numeric value 0.

     Is there any solution? Thanks in advance.

Best regards

Zhang Rui

 

6 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 08 Jun 2016, 01:34 PM
Hello Zhang Rui,

You can handle the valueChanged event and use the set_displayValue to change the display text, the internal value will still remain 0.

Here is sample code:

<script type="text/javascript">
    function valueChanged(textbox, args) {
        if (args.get_newValue() == 0) {
            textbox.set_displayValue("Disabled");
        }
    }
</script>
<telerik:RadNumericTextBox runat="server" ClientEvents-OnValueChanged="valueChanged"></telerik:RadNumericTextBox>

This will also handle the case if the input is empty. You can modify it further like: args.get_newValue() === "0" if needed.

Regards,
Vasil
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Rui
Top achievements
Rank 1
answered on 13 Jun 2016, 03:06 AM

Hello Vasil,

     Thanks for your help. It works, when the value changed to 0, "Disabled" displayed.

     But if I input '0' in the text box then press Enter key, or click the "Down" spin button at this time,  the display text changed back to '0' from "Disabled". It seems the reason is that there is no value-change event to change the display text. How can I solve it?

Best regards

Zhang Rui

0
Vasil
Telerik team
answered on 13 Jun 2016, 07:34 AM
Hi Zhang Rui,

If the enter causes PostBack either because of Default Button in the page or because of AutoPostBack=true for the NumericTextBoxControl. The display value will be formatted server side.

In this case you can handle the PreRender event of the control to set the desired text.

<script type="text/javascript">
function valueChanged(textbox, args) {
    if (args.get_newValue() == 0) {
        textbox.set_displayValue("Disabled");
    }
}
 </script>
<telerik:RadNumericTextBox runat="server"
OnPreRender="Unnamed_PreRender"
ClientEvents-OnValueChanged="valueChanged">
</telerik:RadNumericTextBox>

C#
protected void Unnamed_PreRender(object sender, EventArgs e)
{
 
    RadNumericTextBox textbox = sender as RadNumericTextBox;
    if (textbox.Value == 0)
    {
        textbox.DisplayText = "disabled";
    }
}


Regards,
Vasil
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Rui
Top achievements
Rank 1
answered on 14 Jun 2016, 03:45 AM

Hi Vasil,

    Thanks for your fast response. I've tried your solution, it did not work.

     I do not think it is a PostBack issue. Actually I've disabled auto post back. I think the point is that the internal value still remains 0 when "Disabled" displayed. When you input 0 or click the "Down" spin button, the display text changed to 0, but the internal value did not change. Hence you can not get the value changed event on client side, consquently, the script was not invoked to change the display text.

    Is there any other solution? Thanks.

Best regards

Zhang Rui

 

0
Rui
Top achievements
Rank 1
answered on 16 Jun 2016, 09:45 AM

Hi Vasil,

    Now my problem is that when "Disabled" displayed, the value will be changed to 0 again when I click spin down. Is there any solution?

    Thanks.

Best regards

Zhang Rui

0
Vasil
Telerik team
answered on 16 Jun 2016, 10:22 AM
Hello Rui,

This does not happen with my test page after applying both server side and client side logic.

Could you specify the version of RadControls that you are using and your browser?

Regards,
Vasil
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Input
Asked by
Rui
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Rui
Top achievements
Rank 1
Share this question
or