
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
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.

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.

<%@ 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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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.
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

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.
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

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.
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

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.
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

I'm using the version 2013.2.611.40 of the controls but it has the same behavior.
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