ASP.NET 2.0 Tips & Tricks
Tips & Tricks for ASP.NET 2.0
Rob Howard Telligent Microsoft Regional Director
For more information…
Rob Howard
Email: rhoward@telligent.com Website: telligent.com Blog: weblogs.asp.net/rhoward
Telligent
Community Server (communityserver.org) Custom Application Development (ASP.NET)
Agenda
1. Cross Page Posting 2. Validation Groups 3. Wizard Control and Profile Registration 4. Secure Connection String Storage 5. Config-based Control Registration 6. Caching Features 7. Client Script Goodies, Client Callbacks 8. XML Databinding to build a Blog Reader 9. URL Rewriting 10. Site Map
1. Cross Page Posting
Problem
Postback model isn’t always desired Scenario: Search or lookup button at top of page
New “PostBackUrl” property
Declaratively or programmatically set
Page posted to has strongly typed access
Access controls via “Page.PreviousPage” property <%@ PreviousPage VirtualPath=“a.aspx” %>
Cross Page Posting
2. Validation Groups
Problem
Today validation controls apply “all or nothing”
ASP.NET 2.0 “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
Validation Groups
3. Wizard Control
Problem
Difficult to build Wizard style UI today
Enables linear and non-linear navigation
Developer defines templated “steps” within control Control state maintained throughout wizard steps
Flexible Wizard Control Navigation Model
MoveTo(wizardStep), ActiveStepIndex, etc Events can fire on steps and completion
Wizard Control
4. Connection String Storage
Persistence and declarative referencing
Stored in *.config Avoid hard-coding within pages/code Can be optionally encrypted
Built-in design time support
Promote use for best practices Enable optional encrypting of values in config
Admin Support
MMC Admin Tool Support Configuration API Support
Config Connection Strings
Web.config:
Control Registration
6. Caching
SQL 7 & 2000 Support
Table change dependencies on SQL 7 & 2000 Requires configuration settings One-time setup of SQL Server database Polling model
SQL Server “Yukon”
Result Set dependencies for SQL Yukon Supported through ADO.NET SqlCommand No setup required Notification model
SQL Server 7 & 2000
Table level notifications only
Notification when data in table changes Row-level notification is not supported
Requires one time setup of SQL 7 / 2000
Triggers on tables that participate Stored procedures called to check
Of Note:
Entries in cache table < # of tables in DB Entries in cache = # items in cache table
Data Caching
How it works: SQL 7 & 2000
ASP.NET
Cache
SqlCacheDependency Page DataSet
SQL Server
Northwind Database
Products table
N n1
data
a z
trigger
ChangeNotification table
tableName
aspnet_regsql.exe
changeId
products
3 1
7. Client Script Goodies
Client-side click event handlers on controls:
Focus mechanisms:
Page.SetFocus(control) TextBox.Focus()
Default button and focus