Radcombobox onitemsrequested event not calling javascript function from code behind

1 Answer 69 Views
Top achievements
Rank 1
Javed asked on 23 Jun 2022, 11:44 AM

Hi All,
I am stuck while calling javascript function from code behind on OnItemsRequested event. somehow I can call same js from OnTextChanged event.

below is my code please help-

asp.net -

<telerik:RadComboBox ID="ddl1" runat="server" Height="150" OnClientItemsRequesting="OnClientRequestingAC" OnItemsRequested="ddl1_ItemRequested" EmptyMessage="" EnableLoadOnDemand="true" ShowMoreResultsBox="false" EnableVirtualScrolling="false" AutoPostBack="true" MarkFirstMatch="false" ShowDropDownOnTextboxClick="false" Style="width: 200px; height: 20px !important;" MinFilterLength="3" ForeColor="Black" ShowToggleImage="true" ToolTip="Search by inputing number. Press Enter to select." LoadingMessage="Loading matching records..." OnClientItemsRequestFailed="OnClientACRequestFailedHandler" OnTextChanged="ddl1_TextChanged" OnSelectedIndexChanged="ddl1_SelectedIndexChanged" onkeyup="return CallMethod(event,this.id);">

in server side code-

Protected Sub ddl1_ItemRequested(sender As Object, e As RadComboBoxItemsRequestedEventArgs)
'' Doing some data fetching and JSON request preparation here...

      System.Web.UI.ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "SearchRequestedJS", "GetSearchQueryData('" + JSONrequest + "');", True)

Catch ex As Exception
End Try
    End Sub

1 Answer, 1 is accepted

Sort by
Peter Milchev
Telerik team
answered on 28 Jun 2022, 08:06 AM

Hello Javed,

The main difference between the OnItemsRequested and the OnTextChanged is that the ItemsRequested event is called via a Callback, while the OnTextChanged is triggered on postback. 

Shortly said, you should make the call on the server and inside the ItemsRequested event to create the RadComboBoxItems and return them, instead of relying on calling another web service.

  • https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/load-on-demand/overview 
  • protected void RadComboBox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
       RadComboBox combo = (RadComboBox) o;
       string mdbPath = Server.MapPath("App_Data/NWind.mdb");
       OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath);
       string sql = "SELECT * from Customers WHERE CompanyName LIKE '" + e.Text + "%'";
       OleDbDataAdapter adapter = new OleDbDataAdapter(sql, dbCon);
       DataTable dt = new DataTable();
    // get the Data from the web service instead
    // and create the RadComboBoxItem based on it
       foreach (DataRow row in dt.Rows)
             RadComboBoxItem item = new RadComboBoxItem(row["CompanyName"].ToString());

Peter Milchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Top achievements
Rank 1
commented on 30 Jun 2022, 03:24 PM

Thanks Peter appreciate your help.

Can I call server side function like this?


function A_OnClientItemsRequesting(sender, eventArgs) {
Peter Milchev
Telerik team
commented on 05 Jul 2022, 08:10 AM

Hi Javed, calling a text change in the ItemsRequested is not recommended as this will interfere with the built-in functionality and interrupt the LoadOnDemand. 


Asked by
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question