Title: Cool Tips and Tricks with ASP.NET 2.0
1Cool Tips and Tricks with ASP.NET 2.0
- Stefan Schackow
- Program Manager
- ASP.NET Team
- Microsoft Corporation
2Agenda
- Cross Page Post-backs
- Validation Groups
- Wizard Control
- URL Rewriting/Mapping
- Compilation Build Providers and .WSDL Files
- No-Compile Pages
- Building CMS System w/ File System Provider
- Securing non-ASP.NET web content with Forms
Authentication
- Client Script Goodies, Client Callbacks
- XML Databinding
3Cross Page Posting
- 2.0 Supports Cross Page Postbacks
- Scenario Search or lookup button at top of page
- Postback target via PostBackUrl property
- runatserver/
- Can be declaratively or programmatically set
- Postback target page has full access to server
controls for originating page
- Access controls via Page.PreviousPage property
4Cross-Page Postback Example
natserver ge OnClickBtn1_Click runatserver/
runatserver/ 2 PostBackUrlpage2.aspx runatserver/
Page2.aspx D
im MyCalendar as Calendar PreviousPage.FindContr
ol(MyCalendar) Label1.Text You selected
MyCalendar.SelectedDate alPathpage1.aspx Label1.Text You selecte
d PreviousPage.Exposed Property
5Cross Page Postback
6Validation 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
7ValidationGroup Example
-
-
-
- runatserver/
- ValidationGroupGroup1
- ErrorTextNeed to Fill in Value!
- ControlToValidateTextBox1
-
runatserver/
-
- ValidationGroupGroup2
- ErrorTextNeed to Fill in Value!
- ControlToValidateTextBox2
-
runatserver/
- ValidationGroupGroup1 runatserver/
- oup2 runatserver/
-
-
8Validation Groups
9 Control
- Enables linear and non-linear navigation
- Developer defines templated steps within
control
- Control state maintained throughout wizard steps
- Ideal for multi-step gathering workflow
- Example Usage Customer Registration
- built w/ Wizard
- Flexible Wizard Control Navigation Model
- MoveTo(wizardStep), ActiveStepIndex, etc
- Events can fire both on individual steps and
completion
- Controls in wizard templates flattened to page
- Enables direct control access w/o template fishing
10 Example
- OnFinishButtonClickFinishBtn_Click
-
- titleStep 1
- Enter Name idName runatserver/
-
- titleStep 2
- Enter State idState runatserver/
-
-
- Congrats! The
registration is complete!
-
-
-
- Sub FinishBtn_Click(Sender as Object, E as
WizardNavigationEventArgs)
- Label1.Text Hi Name.Text you are
from State.Text
- End Sub
11Wizard Control
12URL Rewriting/Mapping
- Built-in UrlMapping Module for rewriting paths
- Enables vanity URLs instead of querystrings
- Enables easy moving of pages without 404s
- Useful Performance Tip
- Enables kernel level http caching on IIS6 for
dynamic pages that would need querystrings
spx?tab0 /
mappedUrl/Catalog.aspx?catid1 /
13URL Rewriting
14Compilation Build Providers
- 2.0 introduces concept of Build Providers that
participate in compile process
- Enable declarative file formats as code
resources
- Example Providers Built-in Whidbey
- .WSDL (web service proxies)
- .XSD (data components)
- .RESX (resource files)
- Model of declarative files partial types
enables rich functionality w/ rich extensibility
15Compilation Build Providers
- To build your own custom build provider
- Subclass System.Web.Compilation.BuildProvider
- Register file extension in web/machine.config
defaultLanguage"vb"
type"System.Web.Compilation.PageBuildProvider"
/
type"System.Web.Compilation.UserControlBuildProv
ider" /
To"Web" type"System.Web.Compilation.MasterPageBu
ildProvider" /
pliesTo"Web" type"System.Web.Compilation.WebServ
iceBuildProvider" /
x" appliesTo"Web" type"System.Web.Compilation.We
bHandlerBuildProvider" /
".soap" appliesTo"Web" type"System.Web.Compilati
on.WebServiceBuildProvider" /
ources" type"System.Web.Compilation.ResXBuildProv
ider" /
"Code" type"System.Web.Compilation.WsdlBuildProv
ider" /
"Code" type"System.Web.Compilation.XsdBuildProvid
er" /
16Compilation Build Providers
17No-Compile Pages
- New feature in 2.0 to enable .ASPX pages to be
executed without compilation
- V1 .aspx pages always dynamically compiled
- Two primary scenarios
- Enable site administrators to lockdown ability of
content owners to write code on portions of site
- Enable better scaling for sites with thousands of
pages dont require separate type for each
- Note This is independent of the new
pre-compilation tool which compiles the pages
prior to deployment
18No-Compile Config
-
-
-
- mode Always, Never, Auto
- // Default Always
19No-Compile Pages
20File System Provider
- 2.0 enables web content to be served from
non-file system locations
- Example Database or CMS system
- Developers sub-class VirtualPathProvider
- GetCacheDependency()
- GetFileHash()
- GetFile()
- GetDirectory()
- Tip Can leverage new SqlCacheDependency object
to enable SQL Cache Invalidation
21Simple CMS DB-Driven File Provider
22Securing Non-ASP.NET Content
- 2.0 enables devs to use ASP.NET forms
authentication for non-ASP.NET files
- Static Files .html, .jgp, .gif, .xml, etc
- Dynamic Files .ASP, .PHP, .JSP
- Requires IIS 6.0 (new ExecuteUrl feature)
- ASP.NET executes resource first, then passes
execution flow to originating ISAPI
23Web.Config Security Permissions
/ ystem.web
Admin/
24IIS 6.0 MMC Configuration
25Securing ASP Pages with ASP.NET
26Client Script Goodies
- Client-side click event handlers on controls
- Focus mechanisms
- Page.SetFocus(control)
- TextBox.Focus()
- Default button and focus
-
OnClickButton1_Click OnCl
ientClickClientButton1_Click
runatserver /
27Client Script Goodies
- Validation Error Focus
- SetFocusOnError property
- Auto-scroll maintenance on postback
- Ideal for large pages no code required
- Simplified Client Script Registration
- Page.ClientScript helper methods
- Client-side Event Callbacks
- ICallBackEventHandler interface
- Used by TreeView, GridView controls
28Client Script Goodies
29XML Databinding
- control enables data source
binding against XML files
- Optional XPath expression to scope results
- supports binding against
- Use XPath(expression) statement in templates
- XPathSelect(expression) selects a node list
- Combine two to build simple RSS Reader
30RSS Reader Using XML Databinding
31Summary
- Enormous number of new features in ASP.NET 2.0
- Tons of additional cool features out there
- Visit http//www.asp.net/whidbey to download
slides and samples
- Start exploring ASP.NET 2.0 today!
32ASP.NET Community
- http//www.asp.net/whidbey has whitepapers,
samples, slides and forums dedicated to ASP.NET
2.0
- http//beta.asp.net/quickstart has tons of
samples and source code
- Email
- bradmi_at_microsoft.com
33(No Transcript)