Search code examples
javascriptc#jqueryasp.nettelerik

How to give different empty message for different search option in RadSearchBox?


I have a telerik:RadSearchBox in which,there are three option for searching .For different option the empty message must be different.

For example 1)For Tag / Serial: “Search Tag or Serial Number.” 2)For Staff: “Search Staff ID or Name” 3)For Students: “Search Student ID or Name.”

 <telerik:RadSearchBox RenderMode="Lightweight"   runat="server" ID="RadSearchBox1" Width="250" DropDownSettings-Height="100" MaxResultCount="20">
 <SearchContext ShowDefaultItem="false">
<Items>
<telerik:SearchContextItem Text="Tag / Serial" Key="Tag" />
<telerik:SearchContextItem Text="Staff" Key ="Staff" />
<telerik:SearchContextItem Text="Student" Key ="Student" />
</Items>
</SearchContext>
</telerik:RadSearchBox>

Solution

  • You can capture the change of the selection in the SearchContext, by hooking a click event to the .rsbListItem (which are actually the SearchContextItem) at the OnClientLoad client-side event of the RadSearchBox. Then, depending on the selection, you can use set_emptyMessage("some message"), in order to set it accordingly. Consider the bellow implementation:

    <script type="text/javascript">
        function OnClientLoad(sender) {
            $telerik.$(".rsbListItem").on('click', function (e) {
                switch (this.innerHTML) {
                    case "Tag / Serial":
                        sender.set_emptyMessage("Search Tag or Serial Number");
                        break;
                    case "Staff":
                        sender.set_emptyMessage("Search Staff ID or Name");
                        break;
                    case "Student":
                        sender.set_emptyMessage("Search Student ID or Name");
                        break;
                }
            })
        }
    </script>