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

6 posts, 1 answers
  1. John
    John avatar
    5 posts
    Member since:
    Jul 2011

    Posted 22 Aug 2011 Link to this post

    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?
  2. Answer
    Rory
    Rory avatar
    159 posts
    Member since:
    Jul 2007

    Posted 22 Aug 2011 Link to this post

    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('%');
    }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John
    John avatar
    5 posts
    Member since:
    Jul 2011

    Posted 23 Aug 2011 Link to this post

    That worked great, thanks. Calling clearItems alone forces the combobox to reload from the webservice.

    function SetValue(sender,args)
    {
    sender.clearItems();
    }
  5. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 23 Aug 2011 Link to this post

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

  6. Maulin
    Maulin avatar
    3 posts
    Member since:
    Mar 2016

    Posted 03 Aug in reply to Rory Link to this post

    This doesn't work if radcombobox is on radgrid cell. Any thoughts why?
  7. Peter Milchev
    Admin
    Peter Milchev avatar
    139 posts

    Posted 08 Aug Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017