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

OnTextChanged calling other RadNumericTextBox

12 Answers 796 Views
Input
This is a migrated thread and some comments may be shown as answers.
Marlon Rabara
Top achievements
Rank 2
Marlon Rabara asked on 06 Oct 2008, 07:20 PM

I have a user control in which I have several repeaters. In two of the repeaters, I have two RadNumericText boxes that on a change event does some server side code. The controls themselves are triggers to an Ajax update that updates other controls on other repeaters.

So far I have the logic working with other RadNumericText boxes on the same page but every so often two of these controls will raise the text change event of the other control.

<telerik:RadNumericTextBox ID="DesiredCreditLineTextBox" Runat="server" MinValue="0" Skin="Vista" AutoPostBack="true" OnTextChanged="DesiredCreditLine_TextChanged" />

<telerik:RadNumericTextBox ID="DesiredTermPaymentTextBox" Runat="server" MinValue="0" Skin="Vista" AutoPostBack="true" OnTextChanged="TermPayment_TextChanged" Type="Currency" Width="100px" />

The two controls exist in two different repeaters. In only this one case (I have it working on other controls), the "DesiredTermPaymentTextBox" is raising the "DesiredCreditLine_TextChanged" event.

Any ideas why this anomaly would occur?

 

12 Answers, 1 is accepted

Sort by
0
Missing User
answered on 08 Oct 2008, 07:31 AM
Hello Marlon,

Thank you for contacting us and for the explanation.

I tried to reproduce the problem locally, but to no avail. Can you please check the attached projectand let me know if I am missing something?


Best wishes,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Michael
Top achievements
Rank 2
answered on 15 Dec 2011, 12:24 PM
I am having the same problem. There are 2 RadNumericTextBox Controls on the page.

One containing the Power in kW, the other containing the Power in PS (horsepower).
I want the two textboxes to update each other. For this reasons, the following handlers are implemented:

protected void txtLeistungkW_TextChanged(object sender, EventArgs e)
{
    if (txtLeistungkW.Value == null)
    {
        txtLeistungPS.Value = null;
    }
    else
    {
        txtLeistungPS.Value = txtLeistungkW.Value * 1.36;
    }
}
 
protected void txtLeistungPS_TextChanged(object sender, EventArgs e)
{
    if (txtLeistungPS.Value == null)
    {
        txtLeistungkW.Value = null;
    }
    else
    {
        txtLeistungkW.Value = txtLeistungPS.Value * 0.736;
    }
}

For some reason the second textbox on the page is calling the event handler of the first one, before calling its own event handler. If I change the order of the textboxes, it is the other way around.

Meaning:

If txtLeistungkW appears before txtLeistungPS on the page than the event handler of txtLeistungkW is called when the text of txtLeistungPS is changed. After that the correct event handler is called. The event handler of txtLeistungkW works fine.

If txtLeistungPS appears before txtLeistungkW on the page than the event handler of txtLeistungPS is called when the text of txtLeistungkW is changed. After that the correct event handler is called. The event handler of txtLeistungPS works fine.

The only situation in which this strange behaviour is not happening is when the textbox is empty.
0
Michael
Top achievements
Rank 2
answered on 15 Dec 2011, 12:38 PM
I created a new project with a single page like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="test" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager" EnableScriptCombine="false" runat="server" />
 
        <telerik:RadNumericTextbox id="txtLeistungkW" Type="Number" MinValue="1" runat="server" AutoPostback="true" OnTextChanged="txtLeistungkW_TextChanged">
                <NumberFormat GroupSeparator="" DecimalDigits="0" />
        </telerik:RadNumericTextbox> <strong>kW</strong>
 
        <telerik:RadNumericTextbox id="txtLeistungPS" Type="Number" MinValue="1" runat="server" AutoPostback="true" OnTextChanged="txtLeistungPS_TextChanged">
                <NumberFormat GroupSeparator="" DecimalDigits="0" />
        </telerik:RadNumericTextbox> <strong>PS</strong>
    </div>
    </form>
</body>
</html>

With the same effect. This seems to be a bug in my version of the Telerik Controls.

Edit: I replaced the Telerik RadNumericTextBox controls with ordinary ASP.NET TextBox controls and the problem is gone.
0
Vasil
Telerik team
answered on 16 Dec 2011, 05:05 PM
Hello Krisztian,

The behavior is expected because you change text of the "txtLeistungPS" when handling the txtLeistungkW's TextChanged event.
So the text of txtLeistungPS is changed and indeed the txtLeistungPS_TextChanged will be fired.

Kind 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
Michael
Top achievements
Rank 2
answered on 03 Jan 2012, 08:50 AM
Thanks for looking into it. But I am sure that this is not expected. I think that you haven't read my posts or don't understand the problem.

Why? Because ...

  • The Text of the other Textbox is only changed in the event handler after the postback has already occured. Changing the SelectedValue of a DropDownList won't fire it's SelectedIndexChanged event either. Event handlers don't call other event handlers.
  • The behavior only is present for one of the Textboxes. It isn't even a consistent behavior. The two Textboxes change eachothers Text-Member, but only one calls the other one's event handler? Now that doesn't make sense to me at all.
0
Vasil
Telerik team
answered on 03 Jan 2012, 10:37 AM
Hi Krisztian,

It would not be expected if it happens in the same PostBack. But it actually happens on the next one.

Here is an example:
1. Load the page.
2. Type 50 in the PS textbox.
3. During the PostBack only txtLeistungPS_TextChanged will be executed. And in this point text of kW textbox changes 37.

Now you have two options after the page loads, to change the text of kW or of PS.

A. Now after the page loads you change the text of kW textbox. In this case only txtLeistungkW_TextChanged will be executed, because you have changed it's text one time on server side, and another time on client side. txtLeistungPS_TextChanged will not be executed, since it's text was not changed after the previous PostBack.

B. However if you change the text of PS textbox, then TextChanged of both controls should fire on the next PostBack. This is because text of kW, was changed on server side the previous time and the text of PS was changed in the browser.

About your second question, as what I examine here, it is consistent for both TextBoxes.
If you load the page and enter 5 in the kW and PostBack, the value in PS got's auto-calculated to 7. Then if you change the value of kW to 13 and PostBack again, the TextChanged event will be fired for both controls. Because the value of first one was changed from 5 to 13, and the second one from null to 7. After this auto-calculated value of the PS textbox will become 18.

Now difference that you could see is that when you change the value of PS textbox two times, the second time it will remain the previous value. This happens because the TextChanged of kW is always fired first (when both events are fired), which cause the value of PS value to be changed depending on value of kW.

Kind 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
Michael
Top achievements
Rank 2
answered on 04 Jan 2012, 08:42 AM
Thank you Vasil. Now I understand what is happening.

So what confused me was that the TextChanged event of the Telerik RadNumericTextBox is also fired when the value is altered in the code-behind file. This behavior was unexpected to me. This is not how the ordinary ASP.NET WebControls behave.

Is it possible to turn this feature off?

There is one more thing however. The order in which the event handlers are called is strange. It does not match the order in which the events actually occured. The event of the first TextBox is always called before the event of the other one. This results in the observed behavior that the transformation from kW to PS is working, but the transformation from PS to kW is not.

For example:

1. I Enter 10 into the kW TextBox. This creates an TextChanged event for the PS TextBox, because the Value of PS is altered. The event handler however is not called yet.
2. I Enter 15 into the kW TextBox. Now I would assume that the event from the preivous postback be called before the second TextChanged event of the kW TextBox. But this is not what is happening. First the kW TextBox again overwrites the Value of PS and only than the event handler from the previous postback is called.
0
Vasil
Telerik team
answered on 04 Jan 2012, 10:16 AM
Hi Krisztian,

I did some further debugging and I think I spotted the problem and found some solutions.

The change event is actually not triggered because you change the text server side. It triggers because using DecimalDigits is rounding value on the client. Then after the submit the value is different.

Let see an example:
1. Load the page.
2. Enter 10 in the kW TextBox and submit.
3. ServerSide the value of PS is changed to 13.6 ( which is correct: 10 * 1.36)
4. After the page loads in the browser, the client see 14 (because of DecimalDigits="0"), this value is actually changed client side.
5. Then you again change the value of kW to something else and submit. As a result the Text of PS has changed from 13.6 to 14. Which triggers the TextChanged event.

To fix this behavior I see two options. First one is to use more decimal digits, and the second one is round the value manually before assigning it to the numericTextBox.

Additionally, the TextChanged event is fired in the sequence on which controls appear on the page. There is no information on what time the change happened, this is the normal ASP behavior.

Kind 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
Michael
Top achievements
Rank 2
answered on 04 Jan 2012, 01:01 PM
Thank you for solving this issue.

Since our values are integers I will have to stick to the second solution you suggested. Maybe this behavior could be added to the documentation of your controls? I was looking all over it for a hint and couldn't find anything. Then I found this thread via google.

Anyway, thank you for your kind help.
0
Vasil
Telerik team
answered on 04 Jan 2012, 02:35 PM
Hello,

Thank you for your suggestion. We will add a note in this help article for the case when automatic formatting of the number causes TextChanged event be fired.

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
Mike
Top achievements
Rank 1
answered on 16 Aug 2013, 12:46 PM
Is there another workaround for this issue that doesn't involve rounding prior to binding?  I need to be able to retain the value after the decimal on the backend but also need to display it as a whole number in the control.

I'm using the version 2013.2.611.40 of the controls but it has the same behavior.
0
Vasil
Telerik team
answered on 21 Aug 2013, 06:57 AM
Hello Mike,

You can set KeepNotRoundedValue="true" of the RadNumericTextBox. This way it will keep the full  value, but display it according to the decimal digits set.

Regards,
Vasil
Telerik
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.
Tags
Input
Asked by
Marlon Rabara
Top achievements
Rank 2
Answers by
Missing User
Michael
Top achievements
Rank 2
Vasil
Telerik team
Mike
Top achievements
Rank 1
Share this question
or