Well, its official - I love LINQ. I don't know why but when I say that I think of Steve Correl in the beginning of Anchorman standing there putting mayonnaise in the toaster and saying... "I like to eat ice cream and I really enjoy a nice pair of slacks." Anyways, back to LINQ...
I have worked on a variety of ASP.NET web applications over the past few years and almost all of them needed to collect address data in some form or another. One thing I have never been able to find out there is a decent ASP.NET based user control that allowed the selection of locale (state / province & country.) With this idea in mind, I set out to create my ASP.NET “Locale LINQ” user control.
What It Do
So here are the basic features:
- Displays the corresponding States/Provinces based on the selected Country
- Includes a pretty exhaustive list of Countries & their associated States/Provinces
- Allows for an initial Country or State/Province to be selected via markup or server side code
- Caches the list of States/Provinces & Countries for great performance
- Based on an XML file containing the list of States/Provinces & Countries
- Uses LINQ for all of the data access & queries
- Based on the .NET 3.5 Framework
The following properties are available in the user control ASPX markup:
<uc1:ucLocale ID="ucLocale1" runat="server"
EnableProvinceAutoPostback: Sets whether or not a PostBack occurs when a State/Province is selected
InitialCountrySelected: Sets the initial Country that you would like to be selected when the control is displayed
InitialProvinceSelected: Sets the initial State/Province that you would like to be selected when the control is displayed. Setting this value will also ensure that the related Country is also displayed.
OnSelectedCountryChanged: Event handler for the control's OnSelectedCountryChanged event
OnSelectedProvinceChanged: Event handler for the control's OnSelectedProvinceChanged event
Data & Caching
All of the Province/State & Country information is in the App_Data\CountriesAndProvinces.xml file. I use LINQ to XML to load all of the data from the file and then cache the data in memory after the initial load. Caching the data places it in the server's memory, which will greatly improve performance as a read from the data file will only take place when the cache expires.
// Cache timeout length
public static DateTime CacheTimeout
You can download the control & full source here:
(DO NOT redistribute without my express permission or take credit for my work please.)
I hope that you find this control useful... Please leave comments about what you think about the control & links to sites you use it in.