Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tips and Tricks with ASP.NET 2.0 Bradley Millington Program Manager Web Platform and Tools.

Similar presentations


Presentation on theme: "Tips and Tricks with ASP.NET 2.0 Bradley Millington Program Manager Web Platform and Tools."— Presentation transcript:

1 Tips and Tricks with ASP.NET 2.0 Bradley Millington Program Manager Web Platform and Tools

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 Client Script Goodies, Client Callbacks XML Databinding

3 Cross Page Postbacks 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

5 Cross Page Postbacks demo Bradley Millington Program Manager Web Platform and Tools

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”/> <asp:button text=“Group1” ValidationGroup=“Group1” runat=“server”/> <asp:button text=“Group2” ValidationGroup=“Group2” runat=“server”/>

8 Validation Groups demo Bradley Millington Program Manager Web Platform and Tools

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 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 demo Bradley Millington Program Manager Web Platform and Tools

12 URL Rewriting/Mapping Built-in UrlMapping Module for rewriting paths –Enables “vanity” URLs instead of querystrings –Enables easy moving of pages without 404s

13 URL Rewriting demo Bradley Millington Program Manager Web Platform and Tools

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 demo Bradley Millington Program Manager Web Platform and Tools

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 demo Bradley Millington Program Manager Web Platform and Tools

20 File System Provider 2.0 enables web content to be served from non- file system locations –Example: Database or content system Developers sub-class “VirtualPathProvider”: –GetFileHash() –GetFile() –GetDirectory() –Etc… Tip: Can leverage new SqlCacheDependency object to enable SQL Cache Invalidation

21 Simple DB-Driven Provider demo Bradley Millington Program Manager Web Platform and Tools

22 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” /> Client Script Goodies

23 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 Client Script Goodies

24 demo Bradley Millington Program Manager Web Platform and Tools

25 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

26 RSS Reader Using XML Databinding demo Bradley Millington Program Manager Web Platform and Tools

27 Summary Enormous number of new features in ASP.NET 2.0 –Tons of additional cool features out there… Start exploring ASP.NET 2.0 today!

28 Resources My Slides and Demos –http://www.bradmi.net/presentationshttp://www.bradmi.net/presentations ASP.NET 2.0 Quickstarts –http://www.asp.net/quickstarthttp://www.asp.net/quickstart ASP.NET Forums –http://www.asp.net/forumshttp://www.asp.net/forums

29


Download ppt "Tips and Tricks with ASP.NET 2.0 Bradley Millington Program Manager Web Platform and Tools."

Similar presentations


Ads by Google