This is a migrated thread and some comments may be shown as answers.

Persisting imageUrl/cssClass through PostBack

3 Answers 94 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Paweł Aszklar
Top achievements
Rank 1
Paweł Aszklar asked on 07 Sep 2009, 02:54 PM

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

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 10 Sep 2009, 03:35 PM
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.
0
JD
Top achievements
Rank 1
answered on 19 Sep 2013, 09:40 PM
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");
  });
}
0
Bozhidar
Telerik team
answered on 24 Sep 2013, 08:28 AM
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.
Tags
ListBox
Asked by
Paweł Aszklar
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
JD
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or