This post originated from an RSS feed registered with .NET Buzz
by Steve Hebert.
Original Post: A simple collapsable list user control for list output
Feed Title: Steve Hebert's Development Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/steve.hebert/rss.aspx
Feed Description: .Steve's .Blog - Including .Net, SQL Server, .Math and everything in between
I decided to blog this collapsable list after digging it up recently for another project. The idea is very simple and cleans up processing lists that may result in long/unsightly output on a web page. The code is very simple and straight-forward, no AJAX here - just complete client-side management of the list display. I've removed all style references - apply the styles as you see fit. The summary list is printed using a count parameter, therefore the following style string can be handed to it:
Upon clicking the [+] sign, the actual messages are revealed.
The [-] sign can then be clicked again to hide the content.
Note that the control is coded to allow 1..n instances on a given page. If there aren't any items on the list, nothing is shown on the resulting .aspx page.
Now for the code...
First, we have the HTML for the User Control. Note the use of the server side <DIVs> that enable multiple collapsable list controls per page.
I've always wished that ASP.NET would allow for a <SCRIPT> attribute directly in the ASCX file that would allow you to register it as a once/page scriptlet on a web user control. That would certainly beat spewing the script in the page-behind and using the RegisterClientScriptBlock(...) call.