ASP.NET 2.0 Tips - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

ASP.NET 2.0 Tips

Description:

Scenario: Search or lookup button at top of page. New 'PostBackUrl' property ... can now be registered within web.config files instead of on every page ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 33
Provided by: erik230
Learn more at: http://www.vtdotnet.org
Category:

less

Transcript and Presenter's Notes

Title: ASP.NET 2.0 Tips


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_at_telligent.com
  • Website telligent.com
  • Blog weblogs.asp.net/rhoward
  • Telligent
  • Community Server (communityserver.org)
  • Custom Application Development (ASP.NET)

3
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

4
1. Cross Page Posting
  • Problem
  • Postback model isnt always desired
  • Scenario Search or lookup button at top of page
  • New PostBackUrl property
  • ltaspbutton PostBackUrlb.aspx runatserver/gt
  • Declaratively or programmatically set
  • Page posted to has strongly typed access
  • Access controls via Page.PreviousPage property
  • lt_at_ PreviousPage VirtualPatha.aspx gt

5
Cross-Page Postback Example
  • lt!-- Page1.aspx --gt
  • lthtmlgt
  • ltbodygt
  • ltform runatservergt
  • ltaspbutton textSame Page
    OnClickBtn1_Click runatserver/gt
  • ltaspcalendar idMyCalendar
    runatserver/gt
  • ltaspbutton textPage 2
    PostBackUrlpage2.aspx runatserver/gt
  • lt/formgt
  • lt/bodygt
  • lt/htmlgt
  • Page2.aspx
  • Dim MyCalendar as Calendar PreviousPage.FindCont
    rol(MyCalendar)
  • Label1.Text You selected
    MyCalendar.SelectedDate

6
Cross Page Posting
7
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

8
ValidationGroup Example
  • ltform runatservergt
  • ltasptextbox idTextBox1
    runatserver/gt
  • ltasprequiredfieldvalidator
    ValidationGroupGroup1
  • ErrorTextNeed to Fill in Value!
  • ControlToValidateTextBox1

  • runatserver/gt
  • ltasptextbox idTextBox2 runatserver/gt
  • ltasprequiredfieldvalidator
    ValidationGroupGroup2
  • ErrorTextNeed to Fill in Value!
  • ControlToValidateTextBox2

  • runatserver/gt
  • ltaspbutton textGroup1
    ValidationGroupGroup1 runatserver/gt
  • ltaspbutton textGroup2 ValidationGroupGro
    up2 runatserver/gt
  • lt/formgt

9
Validation Groups
10
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

11
ltASPWizardgt Example
  • ltaspwizard idWizard1 runatserver
    OnFinishButtonClickFinishBtn_Clickgt
  • ltWizardStepsgt
  • ltaspWizardStep idWizardStep1
    titleStep 1gt
  • Enter Name ltasptextbox
    idName runatserver/gt
  • lt/aspWizardStepgt
  • ltaspWizardStep idWizardStep1
    titleStep 2gt
  • Enter State ltasptextbox
    idState runatserver/gt
  • lt/aspWizardStepgt
  • ltaspWizardStep idDone titleCompletegt
  • Congrats! The
    registration is complete!
  • lt/aspWizardStepgt
  • lt/WizardStepsgt
  • lt/aspwizardgt
  • Sub FinishBtn_Click(Sender as Object, E as
    WizardNavigationEventArgs)
  • Label1.Text Hi Name.Text you are
    from State.Text
  • End Sub

12
Wizard Control
13
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

14
Config Connection Strings
Web.config
ltconnectionStringsgt ltadd name"pubs
ProviderName connectionString
/gt lt/connectionStringsgt
Page.aspx
ltaspSqlDataSource IdMySource
ConnectionStringlt connectionStringspubs gt
SelectCommandselect au_id from authors
runatserver/gt
Code.vb
Dim connstr As String ConfigurationSetting
s.ConnectionStrings(pubs)
15
Connection Strings
16
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

lt!-- Web.Config --gt ltcontrolsgt ltadd
tagPrefix"acme" tagName"uc" src"controls/uc.asc
x" /gt ltadd tagPrefix"my" namespace"MyControl
s.Basic" assembly"MyControls" /gt lt/controlsgt
17
Control Registration
18
6. Caching
  • SQL 7 2000 Support
  • Table change dependencies on SQL 7 2000
  • Requires ltcachinggt 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

19
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 lt of tables in DB
  • Entries in cache items in cache table

20
Data Caching
21
How it works SQL 7 2000
ASP.NET
SQL Server
Cache
Northwind Database
Products table
SqlCacheDependency
N n1
data a
DataSet
ChangeNotification table
tableName changeId

3
aspnet_regsql.exe
22
7. Client Script Goodies
  • Client-side click event handlers on controls
  • Focus mechanisms
  • Page.SetFocus(control)
  • TextBox.Focus()
  • Default button and focus
  • ltform DefaultFocuscontrol1 runatservergt
  • ltform DefaultButtonbutton1 runatservergt

ltaspbutton TextPush Me!
OnClickButton1_Click
OnClientClickClientButton1_Click
runatserver /gt
23
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

24
Client Script Goodies
25
8. XML Databinding
  • ltaspXmlDataSourcegt control enables data source
    binding against XML files
  • Optional XPath expression to scope results
  • ltaspDataListgt supports binding against
    ltaspXMLDataSourcegt
  • Use XPath(expression) statement in templates
  • XPathSelect(expression) selects a node list
  • Combine two to build simple RSS Reader

26
RSS Reader
27
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

28
URL Rewriting
29
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

30
Site Map
31
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 slidesdemos from
    http//www.rob-howard.net

32
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 lt_at_ page iemasterpagefileie.
    master gt

33
Dynamic MasterPages
34
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
  • lt_at_ Page UIculturevalue gt
  • Cool Tip You can set value to auto to have it
    automatically based on the client browsers user
    agent string

35
Localization
Write a Comment
User Comments (0)
About PowerShow.com