NumericTextbox.get_value() is returning Old Value OnBlur?

8 posts, 1 answers
  1. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 23 Aug 2012 Link to this post

    Running the August 2012 build - which is currently the latest - this seems to have been introduced in 2012-Q2

    I have some code that allows for Excel style updating in a RadGrid, by sending some information through the onblur event of my RadNumbericTextbox controls.  Until recently this worked great - but now .get_value() returns the old value for the Textbox.  

    I have confirmed that .get_textBoxValue() does give me the correct New value - BUT this will mean quite a bit or rewriting and testing on several pages for me - which I am trying to avoid.

    Before I do that - is this a bug?  Or am I doing something wrong now?

    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
     
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim nActualQty As RadNumericTextBox = TryCast(item.FindControl("nActualQty"), RadNumericTextBox)
            Dim nActualAmount As RadNumericTextBox = TryCast(item.FindControl("nActualAmount"), RadNumericTextBox)
     
            ' This injects a javascript function to do the automatic line calculations
            nActualQty.Attributes.Add("onblur", "calculateLine('" & DataBinder.Eval(e.Item.DataItem, "Is_CPM") & "','" & DataBinder.Eval(e.Item.DataItem, "Rate") & "','" & nActualQty.ClientID & "','" & nActualAmount.ClientID & "')")
     
        End If
     
    End Sub

    function calculateLine(cpm, rate, quantity, totalAmount) {
        var q = parseFloat($find(quantity).get_value()); // This is the WRONG / OLD value
        var q = parseFloat($find(quantity).get_textBoxValue()); // This is now the right value ?!
        var t = $find(totalAmount);
        if (cpm == 'Y') {
            rate = parseFloat(rate) / 1000;
        }
        console.log('rate(' + rate + ') * q(' + q + ')');
        t.set_value(rate * q);
    }

  2. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 23 Aug 2012 Link to this post

    I have confirmed that rolling back to 2012-Q1 makes this problem go away.  This is what I will do for now - but need some direction on whether this is a bug or if I need to redesign our system to do things differently as of Q2.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mike
    Mike avatar
    36 posts
    Member since:
    Sep 2012

    Posted 24 Aug 2012 Link to this post

    We're also seeing the same thing. Can someone from Telerik please respond? Need to know if this is a "bug" or code that now is "working as intended" and we always should have been calling get_textBoxValue().

    Rolling back to Q1 '12 is not an option for us so we want to know if we need to adjust our code to account for this change.

    - Mike Oliver
  5. Answer
    Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 28 Aug 2012 Link to this post

    Hello,

    It is not a bug, indeed the behaviour was changed, but the current is the correct one.

    get_value function return value of the control, and this value is not considered as changed until the control has blurred, enter key is pressed, or set_value is executed.
    Typing into the visible input element of the control does not directly changes its value, the value changes when the user finished its typing with blurring the control for example.

    The get_value will return the new value after the valueChanged event is fired. If you like to access the currently shown value you can use the get_textBoxValue function.

    You can find several more forum threads here for the same issue if you are interested it further details on user scenarios and how they resolved their implementations.

    Greetings,
    Vasil
    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.
  6. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 28 Aug 2012 Link to this post

    That was decidedly not the answer I was hoping for, but thanks for the reply.

    This will mean some careful reworking of some complex pages.
  7. Brock
    Brock avatar
    22 posts
    Member since:
    Mar 2011

    Posted 18 Feb 2013 Link to this post

    I'm having the same issue. My VB.NET code is currently set up to add the clientIDs to my radnumerictextboxes in the code behind.

    Like this:

    Dim calculate As String = "return calculate('" + ddlFacility.ClientID + "','" + rntExistingQuantity.ClientID + "','" + rntExistingWattsPer.ClientID + "','" _
     + rntNewQuantity.ClientID + "','" + rntNewWattsPer.ClientID + "','" + rntUnitIncentive.ClientID + "','" + ddlBonus.ClientID + "','" _
    + rntWattageReduced.ClientID + "','" + rntTotalTherms.ClientID + "','" + rntTotalKW.ClientID + "','" + rntTotalKWH.ClientID + "','" _
    + rntTotalIncentive.ClientID + "');"

                rntExistingQuantity.Attributes.Add("OnBlur", calculate)
                rntExistingWattsPer.Attributes.Add("OnBlur", calculate)

    I currently use get_value() and set_value() since they return numeric values which I can immediately use to perform calculations. However now, since they don't return the current value, I tried using .get_textBoxValue and .set_textBoxValue to get the current value but they return text which breaks my calculations.

    Is there some other method I can use in the above code other than "OnBlur" that will have the same effect as OnBlur prior to this change such that it returns the current value and I can continue to use get_value() and set_value() in my javascript code?

    Otherwise it seems like I'll have to use .get_textBoxValue and .set_textBoxValue but then always cast it as a number just prior to performing my calculations.





  8. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 19 Feb 2013 Link to this post

    Hi Brock,

    The get_value() will return the correct value if the user has finished editing it. During his editing(typing) it is hard to say if the value is valid or not. When the user blurs the input, the get_value will return correct value.

    Instead of handling the OnBlur, you can handle the OnValueChanged client event of the RadNumericTextBox, and perform your logic there.
    If you use textbox.set_value(textbox.get_textBoxValue()) to force setting the value, the get_value will return it correctly even if the input is not blurred.

    Regards,
    Vasil
    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.
  9. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 19 Feb 2013 Link to this post

    We left all of our code in place in the codebehind and just added the control.set_value(control.get_textBoxValue()) before any calculations in the Javascript - as Vasil says.  Example:

           
    function calculateLine(cpm, rate, quantity, totalAmount)
    {
        var q = $find(quantity);
        var t = $find(totalAmount);
     
        //Must use set_value before get_value with Telerik 2012 Q2
        q.set_value(q.get_textBoxValue());
     
        if (cpm == 'Y')
        {
            rate = parseFloat(rate) / 1000;
        }
        console.log('rate(' + rate + ') * q(' + q.get_value() + ')');
        t.set_value(rate * q.get_value());
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017