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

NumericTextbox.get_value() is returning Old Value OnBlur?

7 Answers 543 Views
Input
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 23 Aug 2012, 06:46 PM
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);
}

7 Answers, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 1
answered on 23 Aug 2012, 07:00 PM
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.
0
Mike
Top achievements
Rank 1
answered on 24 Aug 2012, 08:30 PM
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
0
Accepted
Vasil
Telerik team
answered on 28 Aug 2012, 12:36 PM
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.
0
Dan
Top achievements
Rank 1
answered on 28 Aug 2012, 10:16 PM
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.
0
Brock
Top achievements
Rank 1
answered on 18 Feb 2013, 09:15 PM
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.





0
Vasil
Telerik team
answered on 19 Feb 2013, 12:26 PM
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.
0
Dan
Top achievements
Rank 1
answered on 19 Feb 2013, 05:40 PM
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());
}
Tags
Input
Asked by
Dan
Top achievements
Rank 1
Answers by
Dan
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Vasil
Telerik team
Brock
Top achievements
Rank 1
Share this question
or