Persisting imageUrl/cssClass through PostBack

4 posts, 0 answers
  1. Paweł Aszklar
    Paweł Aszklar avatar
    5 posts
    Member since:
    Jul 2009

    Posted 07 Sep 2009 Link to this post

    Hi,

    I have a bit of javascript to populate my RadListBox from WebService when the page is displayed for the first time. Based on some properties in the returned data I want to add imageUrl and/or cssClass to the RadListBoxItems i create. This is what I've come up with:

    -aspx:

    <telerik:RadListBox ID="_rlbBrokers" runat="server" Skin="Default" PersistClientChanges="true"  
            SelectionMode="Multiple" height="200" /> 

    -javascript:

    refreshBrokers: function() {  
            var me = this;  
            var brokersList = me.get_brokersList();  
            this.clearBrokers();  
            this.clearWarehouses();  
            Ewita.WebServices.WarehousesService.GetBrokerItems(this._get_includedBrokerTypes(), this._get_includedWarehouseTypes(), this._permission, this._selectionMode, function(result) {  
                var brokersList = me.get_brokersList();  
                var items = brokersList.get_items();  
                brokersList.trackChanges();  
                var selected = false;  
                for (var i = 0; i < result.length; ++i) {  
                    var broker = result[i];  
                    var brokerItem = new Telerik.Web.UI.RadListBoxItem();  
                    brokerItem.set_text(broker.Name);  
                    brokerItem.set_value(broker.ID);  
                    items.add(brokerItem);  
                    if (broker.IsSelected) {  
                        brokerItem.select();  
                        selected = true;  
                    }  
                    var li = brokerItem.get_element();  
                    if (!broker.IsUserPermitted && !broker.IsActive) {  
                        brokerItem.set_imageUrl("/images/inactive_not_permitted.jpg");  
                        Sys.UI.DomElement.addCssClass(li, "inactive_not_permitted");  
                    }  
                    else if (!broker.IsActive) {  
                        brokerItem.set_imageUrl("/images/inactive.jpg");  
                        Sys.UI.DomElement.addCssClass(li, "inactive");  
                    }  
                    else if (!broker.IsUserPermitted) {  
                        brokerItem.set_imageUrl("/images/not_permitted.jpg");  
                        Sys.UI.DomElement.addCssClass(li, "not_permitted");  
                    }  
                }  
                brokersList.commitChanges();  
                if (selected) {  
                    me._brokersSelect();  
                }  
            });  
        }, 

    It all works perfect until I click a button which causes a postback. I've set PersistClientChanges to true and items, and items selection is preserved, but any css class and image url set in javascript disappears.

    Is there a way to get around this problem?

    I'm using Telerik Controls for ASP.NET AJAX v.2009.2.906.20 (tested also on v.2009.02.826.35), Opera 10.0 browser, .NET Framework 3.5 and Visual Studio 2008.

    Thanks in advance.

    regards 

    Paweł Aszklar

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 10 Sep 2009 Link to this post

    Hi Paweł Aszklar,

    This is bug in the RadListBox. We have already added it in our bug-tracking system, however its priority was not that high. This is the reason why it is not fixed yet. I have tried to find a workaround, however I did not manage to find an easy one.

    Since this looks like a critical problem we will do our best to get it fixed by the beginning of the next week. I will write a follow up as soon as the problem is fixed. You will be able to access the fixed version of the RadListBox using the latest internal build. More information on how to obtain the latest internal can be found here.


    Sincerely yours,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. JD
    JD avatar
    22 posts
    Member since:
    Jul 2013

    Posted 19 Sep 2013 Link to this post

    Is this issue fixed?  I'm having the same issue. After postback, the proper checkbox states are maintained, but all the items' images are set to "greenLogo.gif" - when the javascript only sets the (single) checked one to that image.  The list sits on an ajax panel.

    Thanks!

    OnInit:
    this._RadList.ClientIDMode = System.Web.UI.ClientIDMode.Static;
    this._RadList.ID = "_RadList1";
    this._RadList.Height = Unit.Pixel(200);
    this._RadList.Width = Unit.Pixel(800);
    this._RadList.AllowReorder = true;
    this._RadList.EmptyMessage = "Must choose at least one";
    this._RadList.CheckBoxes = true;
    this._RadList.SelectionMode = ListBoxSelectionMode.Single;
    this._RadList.OnClientItemChecking = "singleSelectionInRgLb";
    this._RadList.OnClientTransferred = "";
    this._RadList.PersistClientChanges = true;
    this._divLists.Controls.Add(this._RadList);

    Javascript:
    function singleSelectionInRgLb(sender, args)
    {
       var item = args.get_item();
       var items = sender.get_items();
       var checked = item.get_checked();
       if (checked == false)
       {
           clearChecks(items)
           item.set_imageUrl("/images/greenLogo.gif");
       }
       else
       {
           item.set_imageUrl("/images/blank.gif");
       }
    }
    function clearChecks(items)
    {
      items.forEach(function (itm)
      {
          itm.set_checked(false);
          itm.set_imageUrl("/images/blank.gif");
      });
    }
  5. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 24 Sep 2013 Link to this post

    Hi Justyn,

    The issue has been fixes. However, the PersistClientChanges property works only for the transfer, reorder and delete operations that are built in the ListBox. For any other custom changes you would have to manually call the trackChanges() and commitChanges() methods of the listbox.
     

    Regards,
    Bozhidar
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top