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

RadCombobox ajax help needed

3 Answers 57 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Gregor Suttie
Top achievements
Rank 1
Gregor Suttie asked on 21 Jun 2010, 01:35 PM
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);
        }

3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 22 Jun 2010, 08:15 AM
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
0
Gregor Suttie
Top achievements
Rank 1
answered on 22 Jun 2010, 08:17 AM

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

 

0
Simon
Telerik team
answered on 23 Jun 2010, 02:09 PM
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
Tags
ComboBox
Asked by
Gregor Suttie
Top achievements
Rank 1
Answers by
Simon
Telerik team
Gregor Suttie
Top achievements
Rank 1
Share this question
or