Cool Tips and Tricks with ASP.NET 2.0
Scott Guthrie General Manager Microsoft Corporation Email: scottgu@microsoft.com Blog: http://weblogs.asp.net/scottgu Website: http://www.scottgu.com
Agenda
App_Offline.htm Cross Page Post-backs Validation Groups Maintaining Scroll Positions Control Focus, Default Buttons, Error Focus Client Scripting and Client Confirmations Data-binding Expressions Config-based Control Registration CSS Control Adapters RSS Feeds and Subscriptions
Download Today
http://weblogs.asp.net/scottgu
App_Offline.htm
Enables you to gracefully take a server application “offline” for maintenance
Useful when making big changes/upgrades
Enabled by adding a “app_offline.htm” file at the root of an application
1) Causes ASP.NET app to shutdown 2) Causes all dynamic requests to return app_offline.htm file contents
Tip: Make sure the app_offline.htm file is large enough (512 bytes) to disable the IE “friendly http errors” feature
App_Offline.htm
Cross Page Post-backs
ASP.NET 2.0 Supports Cross Page Postbacks
Scenario: Search or lookup button at top of page
Postback target via “PostBackUrl” property
Can be declaratively or programmatically set
Postback “target page” has full access to server controls for “originating page”
Access controls via “Page.PreviousPage” property <%@ PreviousPage VirtualPath=“a.aspx” %>
Cross-Page Postback Example:
„ Page2.aspx Dim MyCalendar as Calendar = PreviousPage.FindControl(“MyCalendar”) Label1.Text = “You selected: “ & MyCalendar.SelectedDate
Cross Page Postback
Validation Groups
Enable validation controls to only apply in response to a specific button/action
Today validation controls apply “all or nothing”
Indicated via “ValidationGroup” property
Supported by all Validation and Postback controls Controls in ValidationGroup validate with postback
Programmatic Support for Validating Groups
If (Page.Validate(“group_name”)) Then Page.IsValid evaluates ValidationGroup Postback
ValidationGroup Example:
Validation Groups
MaintainScrollBackPosition
Enable pages to automatically maintain the current scroll position across postbacks
Useful for large pages with input controls
To enable set a page directive attribute
<%@ Page MaintainPostBackPosition=true %>
Cross-browser solution
Works with all modern browsers
MaintainScrollBackPosition
Default Button
Enable developers to identify default button behavior when the “enter” key is hit
Cross browser: works with all modern browsers
Can be set on