RadNumericTextbox - set value with format

7 posts, 0 answers
  1. Kavitha
    Kavitha avatar
    20 posts
    Member since:
    Oct 2012

    Posted 04 Oct 2012 Link to this post

    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.

  2. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 08 Oct 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kavitha
    Kavitha avatar
    20 posts
    Member since:
    Oct 2012

    Posted 08 Oct 2012 Link to this post

    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.

     

  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Oct 2012 Link to this post

    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.
  6. Kavitha
    Kavitha avatar
    20 posts
    Member since:
    Oct 2012

    Posted 16 Oct 2012 Link to this post

    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

  7. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 19 Oct 2012 Link to this post

    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.
  8. Kavitha
    Kavitha avatar
    20 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017