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

Combobox SelectedIndexChanged event not fired

12 Answers 114 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 2
Keith asked on 22 Jun 2013, 04:09 AM
I have a combobox that gets a default item set whenever the data for the combobox control is null. For example a combobox with a list of states for the user to select from. If no valid data exists, the user is presented a default item that says "Select State". If valid data exists, the default item is not set and the data value is set to the combobox.

Our combobox is set to autopostback and update a radlistbox of available items to select from. However, if "Select State" is visible in the combobox and the user selects a state, the SelectedIndexChanged event is not fired and as a result, the radlistbox is not filled with the data. However, if the combobox is changed again to a different state, then the event fires. If valid data is the selected item in the combobox and there is no default item, then the event is fired.

Understanding that the DefaultItem isn't part of the indexed items in the combobox, I can *sort of* understand why the event isn't firing, however, that doesn't resolve the issue that I need to postback whenever the user selects a valid item from the combobox.

How can I get a postback whnenver an item is selected in a combobox (not the default item) when the value being changed from is the default item?

12 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Jun 2013, 05:38 AM
Hi Keith,

The client side and server side SelectedIndexChanged events wont fire when the default item is selected (even if the AutoPostBack property is set to true). This is the default nature and these events will fire instantly once an item other than the default item in the RadComboBox is selected. For these events to fire, it does not require something like what you described : the user need to select an item when the RadComboBox has its default item set and again on selecting another item these events will fire. Please have a look at the following sample code which works as expected.

ASPX:
<telerik:RadComboBox ID="RadCombobox1" runat="server" AutoPostBack="true" Skin="Outlook" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged" OnSelectedIndexChanged="RadCombobox1_SelectedIndexChanged">
    <DefaultItem runat="server" Text="Select States" />
    <Items>
        <telerik:RadComboBoxItem runat="server" Text="State 1" />
        <telerik:RadComboBoxItem runat="server" Text="State 2" />
        <telerik:RadComboBoxItem runat="server" Text="State 3" />
    </Items>
</telerik:RadComboBox>

Thanks,
Shinu.
0
Keith
Top achievements
Rank 2
answered on 24 Jun 2013, 12:29 PM
If that is the case, I must conclude that there is a bug in the control.
Steps to recreate the problem.

1) Populate the RadComboBox with items in the codebehind by binding a datatable to it.
2) Set the DefaultItem text and value, then set it to be selected.

When viewing the page, select the first item in the RadComboBox that IS NOT the default item. SelectedIndexChanged DOES NOT fire.
Select any other item in the list. SelectedIndexChanged DOES fire.

Refresh the page so that the DefaultItem is visible in the RadComboBox, then select any item other than the first item in the list that IS NOT the default item. The SelectedIndexChanged event DOES fire.

Just so we are clear, I am not selecting the default item from the list, I am selecting something else from the list.
An additional reason for me to believe this is a bug is that the client side event "OnClientSelectedIndexChanged" does fire.
0
Keith
Top achievements
Rank 2
answered on 24 Jun 2013, 03:22 PM

Incidently, the code you provided does not work. If you use that code, then select "State 1" from the combobox, the server side event does not fire on postback. Postback does occur however.

If you select any other item from the combobox, the event will fire.

In the meantime, I am using this as a workaround:

if (Request.Form["__EVENTTARGET"] == "RadComboBox1") {
        RadComboBox1_SelectedIndexChanged(RadComboBox1, new EventArgs);
}

This works for me because this is the only event I am handling. Also, to make this work properly, I had to remove the event handlers from the webpage.
0
Nencho
Telerik team
answered on 27 Jun 2013, 11:26 AM
Hello Keith,

I have tested the provided code snippet from Shinu and it seems to behaves correctly at my end. Here is a video, demonstrating it. Please correct me if I had missed something or doing anything wrong.

Regards,
Nencho
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.
0
Keith
Top achievements
Rank 2
answered on 27 Jun 2013, 09:00 PM
I am still not able to coerce the radcombobox to fire the SelectedIndexChanged event when the item changed from is the default item and the item changed to is the first item in the list.

Actually I may know what is causing the problem, but I don't have the internal knowledge of the control to investigate it.

Consider the bug that is present when DefaultItem.Selected = True is issued and later the user issues RadComboBox.SelectedIndex = n ... unless the programmer first sets DefaultItem.Selected = False, the item set by RadComboBox.SelectedIndex = n will not be displayed and the DefaultItem will remain visible.

Perhaps the issue is that the list default item displays whenever the combobox is rendered and overrides the selectedindex value, but that would not explain why it works in your development environment, but not for me.

Please see my test here

Can you verify the Telerik.Web.UI.dll version you are using?

0
Nencho
Telerik team
answered on 01 Jul 2013, 10:46 AM
Hello Keith,

I noticed that you had described this problematic behavior in the other submitted forum ticket. I would like to ask you to continue our conversation in the other thread, in order to keep the correspondence consistent.

Regards,
Nencho
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.
0
Marcos
Top achievements
Rank 2
answered on 24 Feb 2015, 07:56 AM
Hi Keith,

Where did you put this code? I would like to use this workaround since I'm not able to determine why sometimes the event is triggered and sometimes is not.
0
Nencho
Telerik team
answered on 27 Feb 2015, 07:17 AM
Hello Marcos,

The code snippet that Keith demonstrated is used at the Page_Load event, in order to track if the currently triggered postback is caused by the ComboBox and if so - to subscribe for the SelectedIndexChanged event handler.

However, I would like to ask you to elaborate a bit more on your proper scenario. Do you use DefaultItem? In addition, please demonstrate the implementation of the RadComboBox that you use at your end and the scenario, where the issue occurs. Also, specify which version of our controls are you currently using.

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Marcos
Top achievements
Rank 2
answered on 13 Apr 2015, 07:13 AM

Hi Nencho,

 I was actually looking for alternatives, I tried using OnItemChecked instead of the SelectedIndexChanged, but the performance wasn't as good as expected causing more issues.

Now, I'm not using DefaultItem, but I'm manually checking the items of the ComboBox the first time the page is loaded based on the cookies saved before, this is order to help the users to remember the last selection they did:

        public static void SetCheckedItems(RadComboBox comboBox, string sSelectedValues, string sDataType)

        {
            string[] sValues = _common.SplitWords(sSelectedValues);

            foreach (string sValue in sValues)
            {
                if (sValue != String.Empty)
                {

                    RadComboBoxItem item;

                    if (sDataType.Trim().ToLower() == "string")
                        item = comboBox.FindItemByText(sValue);
                    else
                        item = comboBox.FindItemByValue(sValue);

                    if (item != null)
                    {
                        item.Selected = true;
                        item.Checked = true;
                    }

                }

            }


        }

 

This works fine but I cannot find why sometimes the event just doesn't fired at all, I have an stop when the event is fired (SelectedItemChanged) and sometimes when I start testing the control, just doesn't get fired... Now if this issue is related to the manual "checking" of the items, is there any way to save the checked values using the control itself? so it can remember for days the selection made?

I'm using the latest version of the controls 2015.1.401.45

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0
Ivan Danchev
Telerik team
answered on 16 Apr 2015, 07:38 AM
Hello Marcos,

Setting the selected items in the code-behind should not have any effect on whether the event will fire or not. We would like to further investigate why the event is not always firing at your side. I would ask you to isolate a sample project that reproduces the issue, open a support ticket and attach it, because the forum does not allow projects to be attached.

Regards,
Ivan Danchev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Krishna
Top achievements
Rank 1
answered on 24 Jun 2015, 11:55 AM

so 2009 version has java script issues [set checked not working].

It wont even allow you to have server side event.

so what level of testing done for this version.

We are facing issues while migrating.

If I change telerik version ,I have to test entire fuctionality.

Finally using telerik becomes Pathetic choice.

 

 

 

 

0
Ivan Danchev
Telerik team
answered on 29 Jun 2015, 10:09 AM
Hello,

Could you please elaborate more on the issue you are experiencing and specify the exact version of the Telerik controls you are using?

Our controls are thoroughly tested, but it is possible that changes to their functionality or appearance might cause some unexpected and unintended effect when upgrading from such an old version (2009) to the latest. We recommend keeping your controls updated as various improvements and new features are regularly added in subsequent versions.

Please, find linked the following blogpost, which would help you isolate the issue you are having in a sample project and post it for further review.

Regards,
Ivan Danchev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Keith
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Keith
Top achievements
Rank 2
Nencho
Telerik team
Marcos
Top achievements
Rank 2
Ivan Danchev
Telerik team
Krishna
Top achievements
Rank 1
Share this question
or