Ticket T581225
Visible to All Users

ASPxComboBox - How to bind on callbacks of ASPxCallbackPanel

created 7 years ago

Hi,

I'm trying to update ComboBox using ASPxCallbackPanel.

I have two ASPxCallbackPanels as in ProcessSo.aspx.

First one has ASPxComboBoxMarket which gets updated when ASPxButtonRefresh is clicked.
The callback itself is working. I confirmed that ASPxCallbackPanelMarket_Callback gets called and update.
My problem is that ASPxComboBoxMarket.DataBind() doesn't seem to work.
After this function is called, other function ProcessSoSubstituteSku() tries to access ASPxComboBoxParam.SelectedItem.ToString(), but it fails as SelectedIndex = -1 and SelectedItem is null.

Second one has the same issue.

Can you please let me know what am I missing?

Thanks,

Mark

Answers approved by DevExpress Support

created 7 years ago (modified 7 years ago)

Hello Mark,

I found the following issues in the provided code:

  1. The ASPxComboBoxMarket.DataBind method doesn't work because it is necessary to define a data source for the combo box. I recommend you fill the combo box with data before calling the DataBind method. I also want to note that it is necessary to call the DataBind method only when you add items using the DataSource property.
  2. The Refresh button performs postback requests. If you want to refresh the combo box, I recommend you use the client-side ASPxClientComboBox.PerformCallback function instead.
  3. The ViewState of the ASPxComboBoxParam combo box is enabled. But, in this case, it is necessary to update its state on every page request, so I recommend setting the EnableViewState property to false.
    See also:
    The Concept of Callbacks
    The concept of callbacks - Why is it impossible to update external control data during a callback to another control
    ASPxComboBox - Data disappears on the second callback to ASPxCallbackPanel
    I created a sample project and corrected all errors. Please refer to the attachment and let me know if you have further questions.

Updated:

The issue is related to the fact that it is not possible to obtain the selected item in the Page_Init event handler. This is related to the Page Life Cycle specifics. PostData is applied to the control between the Page.Init and Page.Load events. So, if you want to obtain the selected value, please perform this operation in the Page_Load event handler or in the Click event of the button.

    Show previous comments (5)
    DevExpress Support Team 7 years ago

      Hi Mark,

      Thank you for the video. As I can see, the FillParamCombo method is raised only once - on a callback panel's callback request. But please note that ViewState is not updated on callbacks (please refer to the p#2 pf The Concept of Callbacks KB article). So, it is necessary to manually restore the control state on every consequent page request in the Page.Init event handler. To save the state between requests, you can use the Session storage for example:

      C#
      protected void Page_Init(object sender, EventArgs e) { FillCombo((string)Session["combo"]); } protected void ASPxCallbackPanelParam_Callback(object sender, CallbackEventArgsBase e) { string svalue = e.Parameter; Session["combo"] = svalue; FillCombo(svalue); } private void FillCombo(string parameter) { switch (parameter) { case "SO-IMP": ASPxComboBoxParam.Visible = true; ASPxComboBoxParam.ToolTip = "Select AutoPick or Warehouse to Change"; ASPxComboBoxParam.Items.Clear(); ASPxComboBoxParam.Items.Add(new ListEditItem("Auto Pick", 1)); ASPxComboBoxParam.Items.Add(new ListEditItem("MAIN", 2)); ASPxComboBoxParam.Items.Add(new ListEditItem("SEKONJ", 3)); ASPxComboBoxParam.SelectedIndex = 0; break; case "EC-AV": ASPxComboBoxParam.Visible = true; ASPxComboBoxParam.ToolTip = "Select SO Status to Change"; ASPxComboBoxParam.ValueField = "Whouse"; ASPxComboBoxParam.TextField = "Text"; ASPxComboBoxParam.DataSource = Enumerable.Range(0, 5).Select(x => new { Whouse = x, Text = "EC-AV" + x }); ASPxComboBoxParam.DataBind(); ASPxComboBoxParam.SelectedIndex = 2; break; case "PK-WH": ASPxComboBoxParam.Visible = true; ASPxComboBoxParam.ToolTip = "Select BPM SKU to Change"; ASPxComboBoxParam.Items.Clear(); ASPxComboBoxParam.ValueField = "Itemno_id"; ASPxComboBoxParam.TextField = "Text"; ASPxComboBoxParam.DataSource = Enumerable.Range(0, 10).Select(x => new { Itemno_id = x, Text = "PK-WH" + x }); ASPxComboBoxParam.DataBind(); ASPxComboBoxParam.SelectedIndex = 0; break; default: ASPxComboBoxParam.Visible = false; break; } }

      I recommend you take a look at the project from the Answer, where I showed this approach.

        Hi Lex,

        I decided to initialize 3 Parameters in PageLoad and simply hide when they don't need to be seen.
        This way I don't need to fight for CallBack.

        Thank you very much for your support.
        I understood a lot about CallBack.

        Thanks,

        DevExpress Support Team 7 years ago

          I'm happy to hear that you found a workaround, Mark! Feel free to contact us if you have further questions.

          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.