Deleting items client-side doesn’t delete them server-side

3 posts, 0 answers
  1. Simo
    Simo avatar
    5 posts
    Member since:
    Oct 2010

    Posted 11 Nov 2010 Link to this post

    I have a RadListBox showing selected filter rules. I can add items to this ListBox by transferring from other ListBoxes or by creating from other controls' data using client-side javascript. When I add or remove items, I update RadGrid asynchronously using RadAjaxManager. In javascript always when I add or remove items to the ListBox, I call a function to make RadAjaxManager to update RadGrid.

    When I add new items, the items appear in the ListBox client-side and also server-side. But when I remove items, it removes the item client-side and calls the AjaxManager request, but the items are not removed from the server side collection. For example if I add and remove the exactly same item 5 times, then I would have 0 items shown in the client-side ListBox but the same item 5 times in the server-side collection.


    I am using trackChanges() and commitChanges() functions both when adding or deleting items. The ListBox is not posted back. Why is it so that adding items using these functions works but removing doesn’t?





    Here are the functions to add and delete the items and call the Ajax manager (alerts for testing purposes):


    function StateListBoxItemDblClicked() {
         alert("StateListBoxItemDblClicked " + ListboxDestination.get_items().get_count());
         var listBoxSource = $find("<%= UseCaseStateRadListBox.ClientID %>");
         var item = listBoxSource.get_selectedItem();
     function DeleteSelectedItemFromDestination() {
         var item = listboxDestination.get_selectedItem();
         alert("Deleted "+ listboxDestination.get_items().get_count());
    function UseCaseRadGridRebind() {
        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("UseCaseRadGridRebind");


    Here is the RadAjaxManager, RadGrid inside RadPane and RadListBox inside RadPanelBar.


    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
        onajaxrequest="RadAjaxManager1_AjaxRequest" EnableViewState="False">
             <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <telerik:AjaxUpdatedControl ControlID="UseCaseRadGrid" LoadingPanelID="LoadingPanel1" />
            <telerik:RadPane runat="server">
                <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" Skin="Default">
            <telerik:RadGrid ID="UseCaseRadGrid" runat="server" AutoGenerateColumns="False"
                    GridLines="None" Width="440" Visible="true"
                        onneeddatasource="UseCaseRadGrid_NeedDataSource" >
    <ClientSettings EnablePostBackOnRowClick="true">
    <Selecting AllowRowSelect="true" />
           <MasterTableView AutoGenerateColumns="False" ShowHeadersWhenNoRecords="True" EnableNoRecordsTemplate="true">
    <telerik:RadPanelItem Text="Valitut hakuehdot">
        <telerik:RadListBox runat="server" ID="RadListBoxDestination" AutoPostBackOnDelete="false"
            Height="200px" Width="500px" AllowAutomaticUpdates="false" OnClientDeleted="DeleteSelectedItemFromDestination"
    AllowDelete="True" SelectionMode="Multiple" AllowReorder="False" OnClientItemDoubleClicked="DeleteSelectedItemFromDestination"  />

            protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
                if (e.Argument == "UseCaseRadGridRebind")
    RadListBoxItemCollection RadListBoxDestinationItems = RadListBoxDestination.Items;
  2. Genady Sergeev
    Genady Sergeev avatar
    1600 posts

    Posted 17 Nov 2010 Link to this post

    Hello Simo,

    By default, the delete/insert/reorder/transfer operations are saved in the RadListBox client state. Then, after a postback, no matter async or a normal one, the changes are 'played' on the server, the ClientState and the ViewState of the control are updated and the new HTML is sent to the client. However, in your scenario, you haven't added the listbox control to the controls that should be updated by RadAjaxManager. This will result in ClientState not being updated. It is highly likely that this is the reason for the problem that you experience. Please, make sure that RadListBox is updated on every async postback, if there are queued client changes in its client state.

    Sincerely yours,
    Genady Sergeev
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. Simo
    Simo avatar
    5 posts
    Member since:
    Oct 2010

    Posted 18 Nov 2010 Link to this post


    Your advice of adding the listbox to radManager's updated controls was part of the solution, thanks for that. That way I got to work those cases where I create items from comboboxes.

    I was not able to transfer items from other listboxes to the listboxDestination, it gave unpredictable results. Sometimes it added and deleted the items and sometimes not. But when I changed the javascript so that it doesn't transfer the items but creates new ones, then it works like it should.


    function StateListBoxItemDblClicked() {
        //alert("StateListBoxItemDblClicked " + listboxDestination.get_items().get_count());
        var listBoxSource = $find("<%= UseCaseStateRadListBox.ClientID %>");
        var item = listBoxSource.get_selectedItem();
        var newItem = new Telerik.Web.UI.RadListBoxItem();
Back to Top