ListControl Items, Attributes, and ViewState

Posted by: Headlines, on 02 Nov 2005 | View original | Bookmarked: 0 time(s)

ASP.NET 1.x provides four Web controls that serve as list controls:

  • The DropDownList,
  • The CheckBoxList,
  • The RadioButtonList, and
  • The ListBox

One nuisance shared among all controls is the fact that their items don't render attributes. For example, imagine that you wanted to display a CheckBoxList with particular CheckBoxes in the list displayed using a certain CSS class; or maybe when a particular RadioButton in a RadioButtonList control is selected, you want to run some client-side JavaScript. These are features that would be typically set using the CheckBox or RadioButton Web control's Attributes collection. Unfortunately, when a list control is rendered it does not render the attributes of the items.

In a previous article of mine, ListControl Items and Attributes, I discussed one technique for adding attribute support to the ASP.NET 1.x list controls. Specifically, I looked at extending the CheckBoxList class and overriding the Render() method to squirt out the ListItem's attributes. This culminated in a live demo that showed how to create a CheckBoxList that included a 'None' option that, when checked, would use client-side JavaScript to automatically unselect all other checkboxes in the CheckBoxList.

In the article, however, I pointed out one drawback of my code: the attributes specified for the ListItems were not saved in ViewState. That means that these attribute values are not persisted across postbacks; they must be reinjected into the ListControl's ListItems on each postback, as was done in the live demo from the previous article. This article examines how to augment the code examined from the previous article to persist the ListItem attributes in ViewState. Read on to learn more!

I strongly encourage you to first read ListControl Items and Attributes before tackling this article...
Read More >

Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 3383 | Hits: 180

Similar Posts

  • Data-binding Telerik CoverFlow for Silverlight + some Routed Commands goodness more
  • Custom Panels in Silverlight/WPF Part 4: Virtualization more
  • TreeView in ComboBox, take 3 (Silverlight 3, WPF and RadControls) more
  • Scrollable Menu Workaround with a Multi-Column Menu and RadControls for Silverlight more
  • TreeView in a ComboBox dropdown using RadControls for Silverlight more
  • Custom ASP.NET Page Tracing more
  • LinqExtender 1.3.1 more
  • Entity Framework object graphs and viewstate more
  • Login control and ViewState on successful logon more
  • Move the ViewState off the client and cache it on the server more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD