LANGUAGE: All .NET Languages
ASP.NET VERSIONS: 2.0
ASP.NET Whidbey Tips and Tricks
Not all the new features in ASP.NET 2.0 are major, but the minor features are cool, too.
By Brad McCabe
OK, I understand that Whidbey and ASP.NET 2.0 are still about a year away, but I thought I would still take a moment to look at some of the cool new things that you can do in this next version. We've covered some of the tips I'll show you in this article by writing code. I think you'll find that these features we had to develop are much easier for us.
When creating the Infragistics DevCenter (http://DevCenter.Infragistics.Com) I wanted to have a site search option on each page under the menu. To do this I put a text box and button in a user control, then I wrote some code on the button's click event to do a server.transfer to a search page. I put the user's search request in the query string when I did the server.transfer. Currently in ASP.NET when the user clicks the search button, the page is posted back to itself. The button's click event is then called and transfers the page.
In the next version of ASP.NET I would simply add PostTargetURL="Search.Aspx" on the search command button. When the search button was clicked it would post back to the search page directly. The search page would have access to all of the server controls of the original page via the new Page.PreviousPage property.
Today the standard ASP.NET validators are an "all or nothing" event: either all of the validators fire for an action or none of the validators fire. To work around this today, you'd need to work with an out-of-the-box tool, such as Peter Blum's validators solution (http://www.peterblum.com).
In ASP.NET Whidbey, you can hook a validator to a validator group by setting the ValidationGroup property. This can either be done at run time or design time. You can then specify the validator group that various events, such as buttons, belong to in a similar fashion.
Many of the tips and workarounds we've looked at in this column over the past couple of months are now baked right into the Framework. For example, ASP.NET will automatically maintain scroll position between postbacks, and validator controls gain a SetFocusOnError property to set focus to a control if the validator fails.
The last new feature of ASP.NET Whidbey that we will look at is one of my personal favorites: default focus and default buttons. In past columns we have looked at how you can add code to your existing ASP.NET applications to set these actions. In the next generation of ASP.NET you simply add a DefaultFocus and DefaultButton to your form tag. Once this is done, ASP.NET will take and set focus to the specified control when the page loads and default to the specified control when the enter button is pressed.
Over the coming months as more developers get copies of ASP.NET Whidbey (which is now available to MSDN subscribers), we will look at some other Whidbey related tips. Hopefully I have shown you that in addition to all of the major new features that you have heard about in the pages of the December issue of asp.netPRO magazine, Whidbey has many minor usability features that make life much easier for the average developer.
Got a UI question, tip, or idea for a topic you'd like me to cover? I'd love to hear it. E-mail me at [email protected].
Brad McCabe is the technical evangelist for Infragistics. Brad also has been a systems architect and consultant for Verizon Communications and many other clients, and he was a leading .NET evangelist within Ajilon Consulting. His primary interests include ASP.NET, Windows CE .NET, .NET Compact Framework, and Microsoft's networking technologies. E-mail him at [email protected].