RadCombobox ajax help needed

4 posts, 0 answers
  1. Gregor Suttie
    Gregor Suttie avatar
    19 posts
    Member since:
    Oct 2009

    Posted 21 Jun 2010 Link to this post

    Hi There

    I am using a radcombobox box as below:-
     <telerik:RadComboBox ID="radComboFullname" AllowCustomText="true" runat="server" AutoPostBack="true" SkinID="fullnamesearchdropdown" 
                            CausesValidation="False" OnClientItemsRequesting="RequestingHandler" EnableLoadOnDemand="true" 
                            HighlightTemplatedItems="true" ItemRequestTimeout="750" DataSourceID="objDSClientSmartSearch" 
                            DataTextField="fullname" DataValueField="id" TabIndex="1" OnItemsRequested="radComboFullname_ItemsRequested" 
                            OnSelectedIndexChanged="radComboFullname_SelectedIndexChanged"   
                            ShowMoreResultsBox="true" MaxLength="100" IsCaseSensitive="false" LoadingMessage="Searching. Please Wait..." > 
                        </telerik:RadComboBox> 

    When the user types more than 2 characters we go off and try to bring back results to display and that works just fine - when niothing is found however we see the text No Matches which is great, but what I need to have happen is for focus to leave this rad combobox from the code behind within :-
    protected void radComboFullname_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
        if (e.Text.Trim().Length >= 2)
        {
        }
        else
        {
            //move focus off the control
        }
    }            

    How can i accomplish this?


    The javascript we use is also as follows:-
    function RequestingHandler(sender, eventArgs) {
                //restrict ajax request until after 2 chars
                if (eventArgs.get_text().length < 2)
                    eventArgs.set_cancel(true)
                else
                    eventArgs.set_cancel(false);
            }
  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 22 Jun 2010 Link to this post

    Hello Gregor Suttie,

    You cannot alter the state of the RadComboBox in the ItemsRequested event handler. Even scripts emitted there to the client side will not be executed.

    You could achieve this in the client-side ItemsRequested event handler. There you could to the same check for length and focus another element.

    Greetings,
    Simon
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. Gregor Suttie
    Gregor Suttie avatar
    19 posts
    Member since:
    Oct 2009

    Posted 22 Jun 2010 Link to this post

    If a user types in rubbish and no results are found - how can I remove focus from the radcombobox so that the event is cancelled and the drop down is hidden - cant seem to do it from OnClientItemsRequested, is there a way to do it within OnClientItemsRequesting?

    Thanks
    Gregor

     

  4. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 23 Jun 2010 Link to this post

    Hello Gregor Suttie,

    You can prevent drop down opening until Items are loaded by handling the client-side DropDownOpening and ItemsRequested events in this way:
    var preventDDOpening = true;
     
    function onDropDownOpening(sender, eventArgs) {
        eventArgs.set_cancel(preventDDOpening);
        if (!preventDDOpening)
            preventDDOpening = true;
    }
     
    function onItemsRequested(sender) {
        if (sender.get_items().get_count() > 0) {
            preventDDOpening = false;
            sender.showDropDown();
        }
    }

    As to the focus, you can move it in the else body in the ItemsRequested event handler.

    Best wishes,
    Simon
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
Back to Top