| Testing At this point everything is in place to achieve the desired functionality. Build and run your project to test the results. You should be able to launch the DatePicker popup by clicking on the "pick" link. The Calendar control should allow us to go to the next or previous month (via a post-back), just like a regular calendar. Clicking on a particular day should nearly instantly set the value of the TextBox control in the example form, and then close the popup. Possible Problems There are a few places to check if something isn't working properly. First, make sure that the InitializeComponent method in the code-behind file is attaching your DayRenderEventHandler delegate. VS .NET has an odd habit of clearing out the contents of InitializeComponent if you do a lot of switching between Design and HTML mode in your ASPX pages. If the page still doesn't work, you may have a JavaScript error. Remember, JavaScript is case-sensitive. Make sure that you are passing the correct "FormName.FieldName" to the calendarPicker function. When in doubt, debug. VS .NET will even allow you to debug JavaScript code. To debug JavaScript, go to the Internet Options dialog box in Internet Explorer (from the Tools menu). Make sure that "Disable script debugging" is not checked. 
With script debugging enabled, launch your project in debug mode. From the Debug menu, select Windows, and then Running Documents. 
In the Running Documents window, double-click on Default.aspx, and then set a break point in the JavaScript. 
When your browser calls hit the break point, control will switch back to Visual Studio, where you can examine the values of the JavaScript parameters within the script. This is too cool. 
Possibilities for Further Improvement To further reduce the number of postbacks, you could create your own "month picker" control so that users could get to a specific month in one step, without clicking next, next, next. There are lots of ways that you could extend and improve upon this simple example. Conclusion You don't have to forget everything that you knew about Web development prior to .NET. Microsoft has made it easy to extend the out-of-the-box functionality of Web Controls. I hope that this article illustrates that ASP.NET encourages you to be curious about how things work, and to change them. About the Author Conrad Jalali is the co-founder of Useful Studios, a design firm focused on usability. He has been working with Active Server Pages for the past five years, and specializes in ASP.NET with C# and SQL Server 2000. Conrad graduated from Sarah Lawrence College with a Bachelor of Arts in Liberal Arts, and is a Microsoft Certified Professional. He lives in the Washington, DC area, with his wife, Elizabeth, and his dog, Sparky. He can be reached via email at conrad@smallcog.com. << Introduction |