RadNumericTextBox.set_value doesn't work (issue with _initialValueAsText)

3 posts, 0 answers
  1. Marc
    Marc avatar
    39 posts
    Member since:
    Nov 2012

    Posted 06 Aug 2013 Link to this post

    I have code to rollback changes in the UI if the user press the Cancel button. To do so, I remember all values at the beginning and I call set_value(OldValue) when required. It works except in one case for the RadNumberTextBox...

    When the RadNumberTextBox is always enable then it works. But I have a case where a RadNumberTextBox is enabled if a check box is checked, so it's possible that the text box was enabled and now be disabled...I have to re-enable it and set back it's original value.

    With these steps:
    - Original state: the text box is enabled with a value (e.g. 20)
    - 1: the user changed the value to 15
    - 2: the user uncheck the check box...I disable the text box with the set_enabled(false) method
    - 3: the user press the Cancel button...I re-enable the text box and I try to set back the value to 20

    The result is: the value remains to 15!

    Even if I try again to set back the value with set_value(20) it doen't work. But if the user put the focus on the text box, and without changing anything he click again on the Cancel button, then the set_value(20) works!

    By tracing the javascript code while I am calling the set_value() method, I notice that the _initialValueAsText property contains the very first value (20) and not the current value (15), and this property is compared to the new value to know is something need to be changed...the answer is NO CHANGE but in fact it must be. When the user put the focus on the text box then the _initialValueAsText property contains the good value which is the value we see on the screen (15).

    As a patch, I assign the value of _lastSetTextBoxValue (which contains the good value) in _initialValueAsText and then when I call set_value, the comparaison found a change without having the user to click on the text box...

    Can I expect a fix on that?
  2. Vasil
    Vasil avatar
    1540 posts

    Posted 07 Aug 2013 Link to this post

    Hello Marc,

    Use disable() and enable() functions instead of the set_enabled, as suggested in the documentation and it should work properly.

    A bit more information on these fields:

    The _lastSetTextBoxValue keeps the value that the control was set for the visible input internally the last time.
    The _initialValueAsText keeps the value before the user edit.
    The _originalInitialValueAsText keeps the value the value send from server, that to be used in form reset.

    Note that these properties are 'private' and could be changed in any build, so don't use them in production code.

    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 the blog feed now.
  3. DevCraft R3 2016 release webinar banner
  4. Marc
    Marc avatar
    39 posts
    Member since:
    Nov 2012

    Posted 07 Aug 2013 Link to this post

    Hi Vasil, thanks for your reply. Your code doesn't solve my problem but the good new is I found my problem and it wasn't there...

    My check box has no Text attribute, he is in a table where in the first column I have all labels on the second column I have my controls (asp:CheckBox, telerik:RadNumericCheckBox, etc.). What I found is after I changed my value in the text box, when I click on the check box directly then the focus remains on the text box on something like that (the text is hilighted) so the variable _lastSetTextBoxValue is not updated which explain my problems. To fix it I have to specify a Text attribute to my check box and in this case, when I click on it the text box loose the focus. To have a Text attribute without having a text displayed I have to use the value " " because if I use the value "" then the check box is not shown. That explain why when I was clicking again on the text box, then it works.

    So I will consider this as a bug in the ASP Check Box control but maybe if the code in RadNumericTextBox is written differently then this will not happen.

    Anyway I will put  a Text attribute to all my check boxes.

    Thanks for your help.
Back to Top