Peter Blum's replacement for RegisterScript
Peter Blum explains RegisterScripts is a substitute for the System.Web.UI.Page class methods IsClientScriptBlockRegistered, IsStartupScriptRegistered, RegisterClientScriptBlock and RegisterStartupScript. It provides these enhancements to the process of registering scripts:
- It fixes a problem with Microsoft’s methods where they are not always written to the page in a specific order. This WILL break order dependent client-side initialization code on pages where code and controls register 9 or more scripts. If you build a custom control that has ANY order dependent initialization code, in the field your control will break.
- It allows you to omit <script> tags. It inserts them for you, often grouping several scripts under a common tag for better formatting and smaller page size.
- It allows you to determine ordering on the page when scripts are dependant on others that come before them.
He also has a nifty class called AutoSortArrayList, which as he explains: fills a gap in the various collection classes offered within the Microsoft.NET framework. It maintains a list that is always sorted. The list does not use a key to identify each instance. The .NET framework offers similar classes, each with shortcomings.
- ArrayList - Can sort any type of object but cannot automatically add instances into the correct sorted position.
- SortedList - Can keep any type of object in a sorted order. However, it demands a key for every instance. If you don't manage your objects by name, this won't work.
- StringCollection - Can keep a list of strings without the requirement of a key. However, it can't keep them sorted.
AutoSortArrayList extends ArrayList by overriding methods that add, to automatically place objects in the correct position. You can turn on and off this auto sort functionality with a property.
It can sort any type of object, so long as that class implements the IComparable interface or you have a Comparer object. AutoSortArrayList has a property to assign your Comparer object. For instance, if you want to use AutoSortArrayList for strings, assign System.Collections.CaseInsensitiveComparer.
6:48:14 PM
|
|