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

Is it possible to force a combobox to request events every time it is opened?

5 Answers 471 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 22 Aug 2011, 04:33 PM
I have a combobox created server side as so:

myComboBox = new RadComboBox
{
    ID = "myComboBoxID",
    EnableLoadOnDemand = true,
    EnableItemCaching = false,
    ShowMoreResultsBox = false,
    EnableVirtualScrolling = true,
    ItemsPerRequest = -1
};
 
myComboBox.WebServiceSettings.Path = myWebServicePath;
myComboBox.WebServiceSettings.Method = myWebServiceMethod;
myComboBox.OnClientItemsRequesting = myClientItemsRequestingEvent;

with the clientside event defined as:

myClientItemsRequestingEvent = function (sender, eventArgs) {
    var context = eventArgs.get_context();
    context.refID = this.get_myRefID;
};

The webservice call populates the combobox depending on the value of refID. My problem is that this value is dynamic. It changes depending on other elements on the page, and the combobox should be populated appropriately. The problem is, the combobox only seems to call the itemRequestEvent once, when it is opened the first time after page load.

Ideally I would like this event to fire every single time the dropdown is opened, with the combobox being repopulated each time. Is this possible?

5 Answers, 1 is accepted

Sort by
0
Accepted
Rory
Top achievements
Rank 1
answered on 22 Aug 2011, 10:07 PM
Hi John one quick way would be use the OnClientDropDownOpening to add some text that will request all your items.
See Below:

<telerik:RadComboBox ID="cboRecipient" runat="server" 
    EnableLoadOnDemand="true"
    AllowCustomText="false"
    Height="150px" 
    MarkFirstMatch="false"  
    OnClientDropDownOpening="SetValue">
</telerik:RadComboBox>


function SetValue(sender,args)
{
var cbo = $find("<%= cboRecipient.ClientID %>");
       cbo.clearItems();
       cbo.set_text('%');
}
0
John
Top achievements
Rank 1
answered on 23 Aug 2011, 11:06 AM
That worked great, thanks. Calling clearItems alone forces the combobox to reload from the webservice.

function SetValue(sender,args)
{
sender.clearItems();
}
0
Ivana
Telerik team
answered on 23 Aug 2011, 11:11 AM
Hi John,

One solution is to subscribe on client side OnClientDropDownOpening event and initiate a request for items using the client-side requestItems method when the drop-down of the RadComboBox is opening.
Ex:
aspx:
<telerik:RadComboBox ID="RadComboBox1" runat="server" EnableLoadOnDemand="true"
            OnClientDropDownOpening="OnClientDropDownOpening">
        </telerik:RadComboBox>
 
        <script type="text/javascript">
            function OnClientDropDownOpening(sender, arg) {
                if (sender.get_items().get_count() == 0) { 
                    return;
                }
                else {
                    sender.requestItems("parameter", true);
                }
            }
        </script>


Best wishes,
Ivana
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Maulin
Top achievements
Rank 1
answered on 04 Aug 2016, 12:40 AM
This doesn't work if radcombobox is on radgrid cell. Any thoughts why?
0
Peter Milchev
Telerik team
answered on 08 Aug 2016, 03:53 PM
Hello Maulin,

Would you please provide us a sample code snippet showing how the ComboBox is nested in the Grid or a sample project with your implementation of the scenario that does not behave as expected? Thus we could give a more specific answer to your question. 

Regards,
Peter Milchev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
ComboBox
Asked by
John
Top achievements
Rank 1
Answers by
Rory
Top achievements
Rank 1
John
Top achievements
Rank 1
Ivana
Telerik team
Maulin
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or