I recently upgraded from ASP.NET AJAX 2014 to 2022 and ran into an issue with a RadComboBox. It can be reproduced with this code:
Test.aspx
<telerik:RadScriptManager ID="scriptManager" runat="server" />
<telerik:RadComboBox ID="rcb" runat="server" Label="Medication:" AutoPostBack="true"
Width="250" OnSelectedIndexChanged="rcb_SelectedIndexChanged">
<Items>
<telerik:RadComboBoxItem Text="-- select --" Value="" />
<telerik:RadComboBoxItem Text="Benztropine 0.5 mg " />
<telerik:RadComboBoxItem Text="Buspirone 10 MG" />
<telerik:RadComboBoxItem Text="Haloperidol 100mg/ml" />
<telerik:RadComboBoxItem Text="Metaprolol 25 mg" />
<telerik:RadComboBoxItem Text="Quetiapin/Seroquel 400 mg" />
<telerik:RadComboBoxItem Text="Trazadone 150 mg" />
<telerik:RadComboBoxItem Text="Vitamin D2 50,000 units" />
</Items>
</telerik:RadComboBox>
<label>SelectedIndex</label> <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
Test.aspx.cs
protected void rcb_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
Label1.Text = rcb.SelectedIndex.ToString();
rcb.SelectedIndex = 0;
}
When "Benztropine 0.5 mg " is selected, the SelectedIndex in the selected index changed method is incorrectly set to 0, instead of 1. Selecting any other item in the list results in the correct SelectedIndex. I spent a lot of time debugging the code until I noticed that "Benztropine 0.5 mg " has a space at the end.
I found two workarounds:
1. Trim the trailing space from text.
2. Add values for each item.
This was not as issue with the old 2014 version. Is this a bug or am I missing something?
Thanks,
Tim
Hi Tim,
Thank you for reporting this issue!
I was able to see it on my side as well.
It seems that the Text of the selected item is being trimmed internally which makes the selected text and the text of the item in question.
Adding values and removing the trailing space is a feasible way to avoid the problem.
Still, I will need some time to research the issue in detail and I will come back to you with some additional information on the matter.
Hi Tim,
I would like to let you know I have logged this issue as a bug in our system so our developers can research it in more detail.
I have created a public item in our Feedback portal on your behalf, so other developers facing similar issues can find it easily. You can subscribe to the item to get notified of future updates:
In the meantime, you can keep using the workarounds you have already found.
As a small act of gratitude for reporting this problem, I have updated your Telerik points.