Unplanned
Last Updated: 14 Dec 2021 09:56 by ADMIN
Aaron
Created on: 14 Dec 2021 09:39
Category: ListBox
Type: Bug Report
0
Inconsistent Client State

Enabling/Disabling the ListBox on the client is not persisted across PostBacks.

To replicate the issue

ListBox markup

<telerik:RadListBox runat="server" ID="RadListBoxA" CheckBoxes="true" Enabled="false">
    <Items>
        <telerik:RadListBoxItem Text="Item 1" />
        <telerik:RadListBoxItem Text="Item 2" />
        <telerik:RadListBoxItem Text="Item 3" />
        <telerik:RadListBoxItem Text="Item 4" />
    </Items>
</telerik:RadListBox>

<telerik:RadButton runat="server" ID="RadButton1" Text="Toggle State" AutoPostBack="false" OnClientClicked="ToggleListBoxStates" />
<telerik:RadButton runat="server" ID="RadButton2" Text="Postback" AutoPostBack="true" />

 

OnClientClicked event handler

function ToggleListBoxStates(sender, args) {
    var listBoxA = $find("<%= RadListBoxA.ClientID %>");
    listBoxA.trackChanges();
    listBoxA.set_enabled(!listBoxA.get_enabled());
    listBoxA.commitChanges();
}

Run the example, change the ListBox state and do a PostBack.

Notice, the state changes back.

1 comment
ADMIN
Attila Antal
Posted on: 14 Dec 2021 09:56

Hi Aaron,

Thank you for reporting this problem. We had the chance to test this scenario, and the Enabled state is indeed inconsistent.

While testing, we found that the correct client state is sent to the server, but for some reason, this is not restored properly. 

Workaround

Until the issue is fixed, the workaround we could offer would be to access the client-state manually in the Page_Load event and change the ListBox's state on the server based on that.

protected void Page_Load(object sender, EventArgs e)
{
    var serializer = new AdvancedJavaScriptSerializer();

    if (Request.Form[RadListBoxA.ClientStateFieldID] != null)
    {
        var lbAProperties = serializer.Deserialize<ListBoxProperties>(Request.Form[RadListBoxA.ClientStateFieldID]);
        RadListBoxA.Enabled = lbAProperties.isEnabled;
    }
}

class ListBoxProperties
{
    public bool isEnabled { 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.