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

RadSearchBox force postback from SearchContext

1 Answer 173 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 16 Aug 2017, 06:29 PM

How can I force the post back of the RadSearchBox (onSearch event) when someone chooses one of the items from the ContextList? I want to be able to change a secondary list when an item from the ContextSearch is changed (just like they entered something in the search window and clicked search).  I tried to fire the postback of the SearchBox but it doesn't seem to be returning it to the server to process the items selected.  It seems to fire the panel update, but not the server side OnSearch event.

 

                        <telerik:RadSearchBox ID="RadSearchBox1" runat="server" RenderMode="Lightweight"
                                              DataTextField="DiagForList" MaxResultCount="15"
                                              EmptyMessage="Search/Select Order to left"
                                              DataValueField="DiagnosisCodeID"
                                              DataKeyNames="MapField"
                                              style="margin-left: 10px; margin-top: 1px;"
                                              Width="440px" HighlightFirstMatch="True"
                                              SearchContext-Enabled="true"
                                              DataSourceID="SqlDataSourceDG"
                                              OnClientSearch="OnClientSearch"
                                              ToolTip="Select the order from the drop down and/or search for a diagnosis."
                                              OnDataSourceSelect="RadSearchBox1_DataSourceSelect"
                                              OnSearch="RadSearchBox1_Search" MinFilterLength="3">
                        <SearchContext DataSourceID="SqlUpdateABNFlag" DataTextField="MapField" DataKeyField="MapField" DropDownCssClass="contextDropDown"  />
                        <DropDownSettings Width="500px" />
                        <Localization DefaultItemText="All Orders" LoadingItemsMessage="Loading...." />
                        </telerik:RadSearchBox>

 

 

Script:

 

    function pageLoad() {
        var $ = $telerik.$;
        $(".rsbSCSlide ").on("click", ".rsbListItem", function (e) {
            e.preventDefault();
            RaiseClickEvent('RadSearchBox1');
                });

    }
    function RaiseClickEvent(id) {
      __doPostBack(id,'arguments'');
    }

 

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 23 Aug 2017, 03:40 PM
Hello Don,

I am sharing here the resolution of the support ticket for convenience and better visibility from the community.

Subscribing to the selectedIndexChanged event of the search context allows custom handling when a new item of the context dropdown is selected: 

<telerik:RadSearchBox  OnClientLoad="OnClientLoad" ... >
function OnClientLoad(sender, args) {
    var context = sender.get_searchContext();
    var $ = $telerik.$;
    $(context).on({
        "selectedIndexChanged": function (event) {
            // force postback here                             
            alert(1);
        }
    });
}

In order to fire the OnSearch server-side event, one option is to click programmatically the button in the selectedIndexChanged event handler: 

function OnClientLoad(sender, args) {
    var context = sender.get_searchContext();
    var $ = $telerik.$;
    $(context).on({
        "selectedIndexChanged": function (event) {
            var searchbox = $find("<%= RadSearchBox1.ClientID%>");
            if (searchbox.get_text()) {
                searchbox.get_searchButtonElement().click();
            }
        }
    });
}


Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
SearchBox
Asked by
Don
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or