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

RadNumericTextBox.set_value() doesn´t change value at all (ClientSide)

1 Answer 374 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ivo
Top achievements
Rank 1
Ivo asked on 18 May 2017, 07:28 PM

Hello everybody,
I had two RadNumericTextBox TextInicio & TextFin (initial text and final text). 
The rule here is:
The value in TextInicio can not be bigger than TextFin and viceversa. 

So I created a function to check values entered by the user. If one of these values break this rule then it will be necesary to change its value to correct this situation.

The thing is that set_value() is not working; the value remains unset.

I also debugged it with Firefox Developer Tools.

NOTE: Min and Max values are set on server side at page´s Load method. But they usually goes from 1 to 2000.

Are there any others factors I have to take under consideration?
Any ideas about what could be the cause of this??

Am I doing something wrong? If you need something else please let me know.

Here is the code in my page.

01....
02. 
03.    <script type="text/javascript" id="telerikClientEvents1">
04.//<![CDATA[
05. 
06.    function checkValues(sender, args, isInitial) {
07.        var txtIni = $find("<%=TextInicio.ClientID%>");
08.        var ini = txtIni.get_value();       
09. 
10.        var txtFin = $find("<%=TextFin.ClientID%>");
11.        var fin = txtFin.get_value();
12. 
13.        if (ini > fin) // if initial is bigger than final then it is necesary to adjust a value
14.        {
15.            if (isInitial) // which value will be set
16.            {
17.                txtIni.set_value(fin);
18.            }
19.            else
20.            {
21.                txtFin.set_value(ini);
22.            }
23.        }
24.     
25.    } // END of checkValues function
26. 
27.    //]]>
28.    </script>
29. 
30....

 

01.   <telerik:RadScriptManager ID="RadScriptManager1" Runat="server"   EnablePageMethods="True">
02.    </telerik:RadScriptManager>
03.    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" ResolvedRenderMode="Classic">
04.    </telerik:RadWindowManager>
05.    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
06.    </telerik:RadAjaxManager>
07....
08.             <telerik:RadNumericTextBox ID="TextInicio" runat="server" Value="0" DataType="System.Int32" MinValue="1"
09.                <NumberFormat ZeroPattern="n" DecimalDigits="0"></NumberFormat>
10.                <ClientEvents OnValueChanged="function(sender, args){checkValues(sender, args, true);}" />
11.             </telerik:RadNumericTextBox>
12....
13. 
14.             <telerik:RadNumericTextBox ID="TextFin" runat="server" Value="0" DataType="System.Int32" MinValue="1"
15.                <NumberFormat ZeroPattern="n" DecimalDigits="0"></NumberFormat>
16.                <ClientEvents OnValueChanged="function(sender, args){checkValues(sender, args, false);}" />
17.             </telerik:RadNumericTextBox>
18....

 

1 Answer, 1 is accepted

Sort by
0
Ivo
Top achievements
Rank 1
answered on 02 Jun 2017, 10:01 PM

Hello again,
after a huge dive into Telerik´s unorganized documentation I found out the way to solve this issue.

Firsth I had to call my javascript validation function at OnValueChanging client side event handler. With this I had acces to args.get_newValue() and args.set_newValue() methods.

Here is the code

01.function checkInitialValue(sender, args) {
02.        var txtFin = $find("<%=TextFin.ClientID%>");
03.        var ini = args.get_newValue();
04.        var fin = txtFin.get_value();
05. 
06.        if (ini > fin) {
07.            args.set_newValue(fin);
08.        }
09.    }
10. 
11.function checkFinalValue(sender, args) {
12.        var txtIni = $find("<%=TextIni.ClientID%>");
13.        var ini = txtIni.get_value();
14.        var fin = args.get_newValue();
15. 
16.        if (ini > fin) {
17.            args.set_newValue(ini);
18.        }
19.    }

 

The HTML

01.<telerik:RadNumericTextBox ID="TextIni" runat="server" Value="0" DataType="System.Int32" MinValue="1">
02.    <NegativeStyle Resize="None"></NegativeStyle>
03.    <NumberFormat ZeroPattern="n" DecimalDigits="0"></NumberFormat>
04.    <ClientEvents OnValueChanging="checkInitialValue" />
05.</telerik:RadNumericTextBox>
06. 
07.<telerik:RadNumericTextBox ID="TextFin" runat="server" Value="0" DataType="System.Int32" MinValue="1">
08.    <NegativeStyle Resize="None"></NegativeStyle>
09.    <NumberFormat ZeroPattern="n" DecimalDigits="0"></NumberFormat>
10.    <ClientEvents OnValueChanging="checkFinalValue" />
11.</telerik:RadNumericTextBox>

 

This made the difference.
Tags
Input
Asked by
Ivo
Top achievements
Rank 1
Answers by
Ivo
Top achievements
Rank 1
Share this question
or