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

RadNumericTextbox - set value with format

6 Answers 293 Views
Input
This is a migrated thread and some comments may be shown as answers.
Kavitha
Top achievements
Rank 1
Kavitha asked on 04 Oct 2012, 04:29 PM

Hello,

I want to set value of radNumericTextbox in its “OnValueChanging” Client event.

But in OnValueChanging event, I am able to get value of radNumericTextbox using sender.get_value(), but sender.set_value(10.123) returns undefined.

 

So, I tried following method

function OnValueChanging(sender, eventArgs) {

  

    var message;

   

    var target = document.getElementById(sender.get_element().id + '_text');

target.value= 10.123

}

Now, my value is set correctly as 10.123 in radNumericTextBox but without number format.

My radNumericTextbox must have “d” as decimal separator. So it should display 10d123.

Any solutions how set my value with number format in RadNumericTextbox?

Thanks in advance.

6 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 08 Oct 2012, 02:18 PM
Hi Kavitha,

In order to set a value to the RadNumericTextBox you have to use args.set_newValue("10.123"). More information about OnValueChanging client-side event could be fould here.

All the best,
Kostadin
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
Kavitha
Top achievements
Rank 1
answered on 08 Oct 2012, 04:50 PM

Hai Kostadin,

Thanks for the reply.

Your solution worked well if we want to set the new value in the same RadNumericTextbox. But I want to set the new value in another RadNumericTextbox.

If I change a value in first RadNumericTextbox “A” , the new value must be set in second RadNumericTextbox “B”.

For example, my second RadNumericTextbox must display the square of first RadNumericTextBox. If I type 2 in first RadNumerictextbox, the newValue “4” must be set in second RadNumericTextBox.

 

I have set OnvalueChanging() event of first radNumericTextbox which calculates the square number and sets the new value in second radNumericTextBox.

 

Function OnValueChanging(sender, eventArgs) {

var target = document.getElementById('RadNumericTextBox_B');

target.value= sender.get_value()*sender.get_value();

}

This sets the value without format. How can get the “eventArgs” of second RadNumericTextbox here to display with format?

Thanks in advance.

 

0
Princy
Top achievements
Rank 2
answered on 09 Oct 2012, 03:51 AM
Hi Kavitha,

Try the following code to achieve your scenario.

JS:
<script type="text/javascript">
 function OnValueChanged(sender, args)
 {
   var txt = $find("<%= RadNumericTextBox2.ClientID %>");
   var sqr = sender.get_value() * sender.get_value();
   txt.set_value(sqr);
 }
</script>

Thanks,
Princy.
0
Kavitha
Top achievements
Rank 1
answered on 16 Oct 2012, 03:32 PM

Hello Princy,

Thanks for the reply.
Since my controls are generated programmatically, I cannot use control Id directly. Instead I used
$find(sender.get_id().replace()) function as below  to find control in which I want to set the new value instead of $find(“<%=  controlId.ClientID %>”).

             <script type="text/javascript">

function OnValueChanged(sender, args)

{

var txt = $find(sender.get_id().replace("EvaluationColumn_", "Percentage_"));

var sqr = sender.get_value() * sender.get_value();

txt.set_value(sqr);

}

</script>

But I am not able to set value in the second RadNumericTextbox. It gives javascript error “Unable to get value of the property 'toString': object is null or undefined”.

Any solutions how to set the value in the control?

Thanks in advance.
Kavitha

0
Kostadin
Telerik team
answered on 19 Oct 2012, 12:14 PM
Hi Kavitha,

Your approach is right, but I guess you have replaced the wrong IDs. I prepared a sample and attached it to this thread. You can give it a try and see the differences between my project and yours.

All the best,
Kostadin
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
Kavitha
Top achievements
Rank 1
answered on 23 Oct 2012, 02:05 PM

Hi Kostadin,

Yes, my approach was correct and it worked well.

It didn’t work before because of another problem. Now I solved the problem and everything is ok.

Thanks for your help.

Tags
Input
Asked by
Kavitha
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Kavitha
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or