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

Radcombobox SelectedItem reset after postback using Web Service binding method

1 Answer 319 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mozart
Top achievements
Rank 1
Iron
Veteran
Mozart asked on 25 Oct 2019, 09:20 AM

Hello, i have a radcombobox that load filtered data using Web service. The aspx page is like this :

<telerik:RadComboBox runat="server" ID="rcbCustomer" Width="350px"
EmptyMessage="Select Customer" Visible="true" Filter="Contains" MinFilterLength="3"
EnableAutomaticLoadOnDemand="true" EnableLoadOnDemand="true"
AllowCustomText="true" Height="100px" ShowMoreResultsBox="true"
OnItemsRequested="rcbCustomer_ItemsRequested"
EnableVirtualScrolling="true" EnableViewState="true"
OnSelectedIndexChanged="rcbCustomer_SelectedIndexChanged" AutoPostBack="true" CausesValidation="false">
 
<WebServiceSettings Method="GetCustomerName" Path="SalesOrderWebService.asmx"></WebServiceSettings
 
</telerik:RadComboBox>

 

and on my .asmx.cs is like this :

/// <summary>
    /// Summary description for SalesOrderWebService
    /// </summary>
    [WebService(Namespace = "SO.Web.UI")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    [System.Web.Script.Services.ScriptService]
    public class SalesOrderWebService : System.Web.Services.WebService
    {
 
        [WebMethod]
        public RadComboBoxData GetCustomerName(RadComboBoxContext context)
        {
           List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems);
            RadComboBoxData comboData = new RadComboBoxData();
            CustomerCollection colCustomer = new CustomerCollection();
            colCustomer.ListAutoSuggest(context.Text);
            if (colCustomer.Count>0)
            {
                int itemsPerRequest = 10;
                int itemOffset = context.NumberOfItems;
                int endOffset = itemOffset + itemsPerRequest;
                if (endOffset > colCustomer.Count)
                {
                    endOffset = colCustomer.Count;
                }
                if (endOffset == colCustomer.Count)
                {
                    comboData.EndOfItems = true;
                }
                else
                {
                    comboData.EndOfItems = false;
                }
                result = new List<RadComboBoxItemData>(endOffset - itemOffset);
 
                for (int i=0;i<=colCustomer.Count-1;i++)
                {
                    RadComboBoxItemData itemData = new RadComboBoxItemData();
                    itemData.Attributes.Add("CompanyID", colCustomer[i].CustomerId);
                    itemData.Attributes.Add("CompanyName", colCustomer[i].CustomerName);
                    itemData.Value = colCustomer[i].CustomerId.ToString();
                    itemData.Text = colCustomer[i].CustomerName;
                    result.Add(itemData);
                }
                comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), colCustomer.Count.ToString());
            }
            else
            {
                comboData.Message = "No matches";
            }
            comboData.Items = result.ToArray();
            return comboData;
        }
    }

 

When i try to debug on page load after i select an item on rcbCustomer it always show as null.

What should i do to fix this ? 

I'm using telerik.web.ui version 2016.3.1027.45.

 

Thank you in advance.

1 Answer, 1 is accepted

Sort by
0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 29 Oct 2019, 02:56 PM

Hi Mozart,

Thank you for providing the WebService and RadCombobox markup. The reason the RadCombobox is null during Page_load is because LoadOnDemand requests the items when the filter is changed. In this case, the minimum filter length is 3. Additionally, since the WebService is passing items to the RadCombobox, the Page_Load event will not fire when requesting items.

If you would like to Pass Context Information to the Server, we have a Load On Demand Modes demo available.

I hope this helps. Please let me know if you need any additional information. Thank you.

Regards,


Eric R | Technical Support Engineer
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Mozart
Top achievements
Rank 1
Iron
Veteran
Answers by
Eric R | Senior Technical Support Engineer
Telerik team
Share this question
or