or

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
<% Html.Telerik().Editor() .Name("txtArea") .Tools(tools => tools .Clear() .Bold().Italic().Underline() .JustifyLeft().JustifyCenter().JustifyRight() .InsertUnorderedList().InsertOrderedList() .Indent().Outdent() ).HtmlAttributes(new { style = "display:inline;height:50;width:500;", @readonly="readonly", @disabled="disabled" }) .ClientEvents(events => events.OnChange("change")) .Value(HttpUtility.HtmlDecode(EnglishWording)) .Render(); %>protected void Page_Load(object sender, EventArgs e) { if (Session["GridData"] == null) { DataTable table = GetTable(); Session.Add("GridData", table); } DefineGridStructure(); } private void DefineGridStructure() { RadGrid grid = new RadGrid(); grid.ID = "RadGrid1"; grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource); grid.AutoGenerateEditColumn = true; grid.AutoGenerateDeleteColumn = true; grid.AllowAutomaticInserts = false; grid.Width = Unit.Percentage(100); grid.PageSize = 15; grid.AllowPaging = true; grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; grid.AutoGenerateColumns = false; grid.MasterTableView.Width = Unit.Percentage(100); grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom; grid.AllowAutomaticDeletes = false; grid.AllowAutomaticUpdates = false; grid.InsertCommand +=grid_InsertCommand; grid.MasterTableView.DataKeyNames = new string[] { "RowNumber" }; GridBoundColumn boundColumn = new GridBoundColumn(); boundColumn.DataField = "RowNumber"; boundColumn.HeaderText = "RowNumber"; boundColumn.ReadOnly = true; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Size"; boundColumn.HeaderText = "Size"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Description"; boundColumn.HeaderText = "Description"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Quantity"; boundColumn.HeaderText = "Quantity"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Duration"; boundColumn.HeaderText = "Duration"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "DurationType"; boundColumn.HeaderText = "DurationType"; grid.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "Amount"; boundColumn.HeaderText = "Amount"; grid.MasterTableView.Columns.Add(boundColumn); PlaceHolder1.Controls.Add(grid); } private void grid_InsertCommand(object sender, GridCommandEventArgs e) { // Looking to loop through the form so i can insert the values into the datatable } void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { DataTable current = (DataTable)Session["GridData"]; RadGrid grid = (RadGrid)sender; grid.DataSource = current; } static DataTable GetTable() { // // Here we create a DataTable with a few columns. // // Create Datatable to store all colums DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("RowNumber", typeof(string))); dt.Columns.Add(new DataColumn("Size", typeof(string))); dt.Columns.Add(new DataColumn("Description", typeof(string))); dt.Columns.Add(new DataColumn("Quantity", typeof(string))); dt.Columns.Add(new DataColumn("Unit", typeof(string))); dt.Columns.Add(new DataColumn("Duration", typeof(string))); dt.Columns.Add(new DataColumn("DurationType", typeof(string))); dt.Columns.Add(new DataColumn("Amount", typeof(string))); dr = dt.NewRow(); dr["RowNumber"] = 1; dr["Size"] = string.Empty; dr["Description"] = string.Empty; dr["Quantity"] = string.Empty; dr["Unit"] = string.Empty; dr["Duration"] = string.Empty; dr["DurationType"] = string.Empty; dr["Amount"] = string.Empty; dt.Rows.Add(dr); return dt; }