Download presentation
Presentation is loading. Please wait.
Published byJunior Harris Modified over 9 years ago
1
Cool Tips and Tricks with ASP.NET 2.0 Stefan Schackow Program Manager ASP.NET Team Microsoft Corporation
2
Agenda 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
3
Cross Page Posting 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
4
Cross-Page Postback Example: ‘ Page2.aspx Dim MyCalendar as Calendar = PreviousPage.FindControl(“MyCalendar”) Label1.Text = “You selected: “ & MyCalendar.SelectedDate Label1.Text = “You selected: “ & PreviousPage.Exposed Property
5
Cross Page Postback
6
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
7
ValidationGroup Example: <asp:requiredfieldvalidator ValidationGroup=“Group1” ErrorText=“Need to Fill in Value!” ControlToValidate=“TextBox1” runat=“server”/> <asp:requiredfieldvalidator ValidationGroup=“Group2” ErrorText=“Need to Fill in Value!” ControlToValidate=“TextBox2” runat=“server”/>
8
Validation Groups
9
Control 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: Example: Enter Name: Enter State: 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
11
Wizard Control
12
URL 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
13
URL Rewriting
14
Compilation 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
15
Compilation Build Providers To build your own custom build provider: Subclass System.Web.Compilation.BuildProvider Register file extension in web/machine.config
16
Compilation Build Providers
17
“No-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 – don’t require separate type for each Note: This is independent of the new pre-compilation tool – which compiles the pages prior to deployment
18
“No-Compile” Config [mode] = “Always”, “Never”, “Auto” // Default: Always
19
No-Compile Pages
20
File 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
21
Simple CMS DB-Driven File Provider
22
Securing 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
23
Web.Config Security Permissions
24
IIS 6.0 MMC Configuration
25
Securing ASP Pages with ASP.NET
26
Client Script Goodies Client-side click event handlers on controls: Focus mechanisms: Page.SetFocus(control) TextBox.Focus() Default button and focus <asp:button Text=“Push Me!” OnClick=“Button1_Click” OnClientClick=“ClientButton1_Click” runat=“server” />
27
Client 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
28
Client Script Goodies
29
XML 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
30
RSS Reader Using XML Databinding
31
Summary 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!
32
ASP.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@microsoft.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.