1 / 32

ASP.NET 2.0 Tips & Tricks Tips & Tricks for ASP.NET 2.0

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)

benoit
Télécharger la présentation

ASP.NET 2.0 Tips & Tricks Tips & Tricks for ASP.NET 2.0

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.NET 2.0 Tips & TricksTips & Tricks for ASP.NET 2.0 Rob Howard Telligent Microsoft Regional Director

  2. 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)

  3. Agenda • Cross Page Posting • Validation Groups • Wizard Control and Profile Registration • Secure Connection String Storage • Config-based Control Registration • Caching Features • Client Script Goodies, Client Callbacks • XML Databinding to build a Blog Reader • URL Rewriting • Site Map

  4. 1. Cross Page Posting • Problem • Postback model isn’t always desired • Scenario: Search or lookup button at top of page • New “PostBackUrl” property • <asp:button PostBackUrl=“b.aspx” runat=“server”/> • Declaratively or programmatically set • Page posted to has strongly typed access • Access controls via “Page.PreviousPage” property • <%@ PreviousPage VirtualPath=“a.aspx” %>

  5. Cross Page Posting

  6. 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

  7. Validation Groups

  8. 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

  9. Wizard Control

  10. 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

  11. Config Connection Strings Web.config: <connectionStrings> <add name="pubs“ ProviderName=“…” connectionString=“…” /> </connectionStrings> Page.aspx: <asp:SqlDataSource Id=“MySource” ConnectionString=“<%$ connectionStrings:pubs %>” SelectCommand=“select au_id from authors” runat=“server”/> Code.vb: Dim connstr As String = ConfigurationSettings.ConnectionStrings(“pubs”)

  12. Connection Strings

  13. 5. Web.Config Registration of Controls • Server controls can now be registered within web.config files instead of on every page • Full Visual Studio support w/ intellisense <!-- Web.Config --> <controls> <add tagPrefix="acme" tagName="uc" src="controls/uc.ascx" /> <add tagPrefix="my" namespace="MyControls.Basic" assembly="MyControls" /> </controls>

  14. Control Registration

  15. 6. Caching • SQL 7 & 2000 Support • Table change dependencies on SQL 7 & 2000 • Requires <caching> 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

  16. 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

  17. Data Caching

  18. Page z trigger products 1 How it works: SQL 7 & 2000 ASP.NET SQL Server Cache Northwind Database Products table SqlCacheDependency DataSet ChangeNotification table 3 aspnet_regsql.exe

  19. 7. Client Script Goodies • Client-side click event handlers on controls: • Focus mechanisms: • Page.SetFocus(control) • TextBox.Focus() • Default button and focus • <form DefaultFocus=“control1” runat=“server”> • <form DefaultButton=“button1” runat=“server”> <asp:button Text=“Push Me!” OnClick=“Button1_Click” OnClientClick=“ClientButton1_Click” runat=“server” />

  20. 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

  21. Client Script Goodies

  22. 8. XML Databinding • <asp:XmlDataSource> control enables data source binding against XML files • Optional XPath expression to scope results • <asp:DataList> supports binding against <asp:XMLDataSource> • Use “XPath(expression)” statement in templates • “XPathSelect(expression)” selects a node list • Combine two to build simple RSS Reader

  23. RSS Reader

  24. 9. URL Rewriting • Enable vanity URLs • Eliminate ugly query string URLs • Simplifies customer navigation experience • Possible in ASP.NET 1.1 • Required custom code • Ex., Community Server • ASP.NET 2.0 • Simply edit configuration file • Add/Remove/Clear mappings

  25. URL Rewriting

  26. 10. Site Map • How to manage all the site urls • Many navigation points • What is the relationship between these points • Possible in ASP.NET 1.1 • Write a complete site map • Ex., Community Server • ASP.NET 2.0 • Site Map is a built in feature (Provider based) • Makes adding URLs/Pages unbelievably easy

  27. Site Map

  28. Summary • Enormous number of new features in ASP.NET 2.0 • Tons of additional cool features out there… • Visit http://beta.asp.net/quickstarts to try out hundreds of samples online • Download these slides+demos from: http://www.rob-howard.net

  29. 10. Dynamic Master Pages • Master pages encapsulate layout • Enforce a consistent look and feel across pages • Master pages can be dynamically chosen • Scenario: Per browser type or per customer type • Two mechanisms to set dynamically change master: 1) Set Page.MasterPageFile property in Page_PreInit event 2) Device Filter: <%@ page ie:masterpagefile=“ie.master” %>

  30. Dynamic MasterPages

  31. 10 Localization • Whidbey supports nice localization model • Store strings and values in a separate .resx file • Culture and language settings • programmatically and declaratively set • Override InitalizeCulture on the Page class • <%@ Page UIculture=“value” %> • Cool Tip: You can set value to “auto” to have it automatically based on the client browser’s user agent string

  32. Localization

More Related