RadComboBox Web Service Requests are received at wrong times

1 Answer 36 Views
ComboBox UI for ASP.NET AJAX in ASP.NET MVC
Dante
Top achievements
Rank 1
Dante asked on 04 Oct 2022, 09:37 AM

I'm using a RadComboBox to search through clients via WebService


<telerik:RadComboBox ID="txtcontraente" runat="server" EmptyMessage="Seleziona un cliente" LoadingMessage="Caricamento in corso..." WebServiceSettings-Method="GetText" WebServiceSettings-Path="/Modules/WS/TContraente_radws_fullname.asmx" MinFilterLength="3" EnableLoadOnDemand="true" MarkFirstMatch="false" Style="max-width: 300px" Width="100%" OnClientKeyPressing="OnClientKeyPressing" DropDownWidth="400px">

    <ClientItemTemplate>
        <table style="width: 100%;">
            <tr>
                <td>#= Attributes.Nominativo #
                </td>
                <td style="text-align: right;">#= Attributes.DataNascita #
                </td>
            </tr>
            <tr>
                <td>#= Attributes.Convenzione #
                </td>
                <td style="text-align: right;">#= Attributes.Societa #
                </td>
            </tr>
        </table>
        <hr style="padding: 0px; margin: 0px;"></hr>
    </ClientItemTemplate>
</telerik:RadComboBox>

The problem I'm having is that sometimes requests overlap and are received at wrong times.
E.g. I search for 'abcd' (which would yield no results), then I delete the 'd' and search becomes 'abc' (which should yield results).
The problem is that sometimes the 'abcd' request is received after the 'abc' request, thus yielding no results.

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 07 Oct 2022, 07:54 AM

Hello Dante,

I have made a few tests and the ComboBox seems to be working as expected.

Here is a short video showing that: http://somup.com/c36ii7veV5

Please double-check our documentation for the WebService and Client Templates to see if there is anything missing.

 

If you wish to test my sample, below you can find the entire code I used.

Default.aspx

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>

        <telerik:RadComboBox ID="txtcontraente" runat="server" EmptyMessage="Seleziona un cliente"
            LoadingMessage="Caricamento in corso..."
            WebServiceSettings-Method="GetText"
            WebServiceSettings-Path="/Modules/WS/TContraente_radws_fullname.asmx"
            MinFilterLength="3" EnableLoadOnDemand="true" MarkFirstMatch="false"
            DataModelID="Id"
            Style="max-width: 300px" Width="100%"
            OnClientKeyPressing="OnClientKeyPressing" DropDownWidth="400px">

            <ClientItemTemplate>
        <table style="width: 100%;">
            <tr>
                <td>#= Attributes["Nominativo"] #
                </td>
                <td style="text-align: right;">#= Attributes["DataNascita"] #
                </td>
            </tr>
            <tr>
                <td>#= Attributes["Convenzione"] #
                </td>
                <td style="text-align: right;">#= Attributes["Societa"] #
                </td>
            </tr>
        </table>
        <hr style="padding: 0px; margin: 0px;"></hr>
            </ClientItemTemplate>
        </telerik:RadComboBox>

        <script>
            function OnClientKeyPressing(sender, args) {

            }
        </script>
    </form>
</body>
</html>

 

TContraente_radws_fullname.asmx.cs

using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.Services;
using Telerik.Web.UI;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class TContraente_radws_fullname : System.Web.Services.WebService
{
    [WebMethod]
    public RadComboBoxItemData[] GetText(object context)
    {
        IDictionary<string, object> contextDictionary = (IDictionary<string, object>)context;
        string filterString = ((string)contextDictionary["Text"]).ToLower();

        List<MyClass> myData = ComboSource()
            .Where(x => x.Nominativo.ToLower().Contains(filterString) || 
                        x.Societa.ToLower().Contains(filterString) || 
                        x.Convenzione.ToLower().Contains(filterString))
            .ToList();

        List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(myData.Count);

        foreach (MyClass data in myData)
        {
            RadComboBoxItemData itemData = new RadComboBoxItemData();

            itemData.Attributes.Add("Nominativo", data.Nominativo);
            itemData.Attributes.Add("DataNascita", data.DataNascita);
            itemData.Attributes.Add("Convenzione", data.Convenzione);
            itemData.Attributes.Add("Societa", data.Societa);

            itemData.Text = data.Nominativo;
            itemData.Value = data.Id.ToString();
            result.Add(itemData);
        }
        return result.ToArray();
    }

    private List<MyClass> ComboSource()
    {
        return Enumerable.Range(1, 50).Select(x => new MyClass()
        {
            Id = x,
            Nominativo = "ABC " + x,
            DataNascita = "DataNascita " + x,
            Convenzione = "Convenzione " + x,
            Societa = "Societa " + x,
        }).ToList();
    }

    public class MyClass
    {
        public int Id { get; set; }
        public string Nominativo { get; set; }
        public string DataNascita { get; set; }
        public string Convenzione { get; set; }
        public string Societa { get; set; }
    }


}

 

Regards,
Attila Antal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ComboBox UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Dante
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or