Ticket T219865
Visible to All Users

ComboBox - Set Selected Value from JavaScript in Callback Mode

created 10 years ago (modified 10 years ago)

I have a combobox as this (information is retrieved in pages of 30 records).
@model AutomotoraWeb.Models.ConsultaVentaModel
@using System.Web.UI.WebControls

@Html.DevExpress().ComboBoxFor(model => model.Cliente.Codigo,
    settings =>
    {
        settings.Name = "comboBox3";
        settings.Width = 530;
        //settings.SelectedIndex = 0;
        settings.Properties.DropDownWidth = 550;
        settings.Properties.DropDownStyle = DropDownStyle.DropDownList;

settings.CallbackRouteValues = new { Controller = "ConsultasFin", Action = "ListClientesCuotas" };
        settings.Properties.CallbackPageSize = 30;
        //settings.Properties.TextField = "Nombre";
        settings.Properties.ValueField = "Codigo";
        //settings.Properties.ClearButton.Visibility = AutoBoolean.True;
        settings.Properties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
        settings.Properties.ClientSideEvents.SelectedIndexChanged = "ComboClientesChanged";
        //settings.Properties.ClientSideEvents.SelectedIndexChanged = "function(s, e) {alert(s.GetValue())}";
    }
    ).BindList(ViewData["ClientesCuotas"]).GetHtml()

I want to set the selected value from javascript, when the user enters a code a press a button, the javascript captures the inputed code and then selects the corresponding value in the combobox.
The javascrips looks like this. The second line is the one that should be modified, I just include it to show the idea:

var selectedCli = $("#txCodigoCli").val();
 comoBox3.selectedValue = selectedCli  //if selectedCli is not in the current page, it should be retreived from the server to display the name corresponding to the code.

Thanks
Mariel

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hello Mariel,

Please note that when ComboBox is used in callback mode, the ASPxClientComboBox.SetValue method cannot be used to select items that are not currently displayed within the editor's window. In this scenario, I recommend that you send a request to the server by calling ASPxClientComboBox.PerformCallback and update the model on the server side. A similar approach is implemented in the E2844: MVC ComboBox Extension - Cascading Combo Boxes code example for the depended "City" ComboBox.

If you need to check if a corresponding item was already loaded to the ComboBox before sending the request, use ComboBox and the embedded ListBox API for this purpose:

ASPxClientComboBox.GetItemCount
ASPxClientComboBox.GetItem
ASPxClientListEditItem.value

Let me know if this information helps.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.