Title: Marco Bellinaso
1What's New with Visual Studio 2005 and ASP.NET 2.0
- Marco Bellinaso
- Senior Trainer Consultant
- Code Architects Srl
- Web http//www.codearchitects.com
- E-mail mbellinaso_at_codearchitects.com
2New Features at a Glance
Data Controls
Login Controls
Web Parts
Other New Controls
Controls
Master Pages
Themes and Skins
Localization
Compilation
Page Framework
Membership
Role Management
Profiles
Configuration
Services and APIs
Site Maps
Health Monitoring
Other Services
3What's New in Data Access
- Data source controls
- Declarative 2-way data binding
- Data controls
- GridView - Like the DataGrid, only better
- DetailsView - Companion to GridView
- SQL cache dependencies
- Key cached items to database entities
- Simplified data binding expressions
4ASP.NET 1.x Data Binding
ltaspDataGrid ID"MyDataGrid" RunAt"server" /gt
... ltscript language"C" runat"server"gt void
Page_Load (Object sender, EventArgs e)
SqlConnection connection new SqlConnection
("serverlocalhostdatabasepubsintegrated
securitytrue") try
connection.Open () SqlCommand command
new SqlCommand ("select title_id,
titles, price from titles")
MyDataGrid.DataSource command.ExecuteReader
() MyDataGrid.DataBind ()
finally connection.Close ()
lt/scriptgt
5ASP.NET 1.x Data Binding
ltaspDataGrid ID"MyDataGrid" RunAt"server" /gt
... ltscript languageVB" runat"server"gt Sub
Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Dim connection As New
SqlConnection _ ("serverlocalhostdatabasepubs
integrated securitytrue") Try
connection.Open() Dim command As New
_ SqlCommand("select title_id, titles, price
from titles") MyDataGrid.DataSource
command.ExecuteReader()
MyDataGrid.DataBind() Finally
connection.Close() End Try End Sub lt/scriptgt
6ASP.NET 2.0 Data Binding
ltaspSqlDataSource ID"Titles" RunAt"server"
ConnectionString"serverlocalhostdatabasepubsi
ntegrated securitytrue" SelectCommand"select
title_id, title, price from titles"
/gt ltaspDataGrid DataSourceID"Titles"
RunAt"server" /gt
7Declarative Data Binding
Name Title Microsoft Corporation
8What's New for UIs
- Master pages
- "Visual inheritance" for Web pages
- Applied declaratively or programmatically
- Themes and skins
- Theme controls, pages, and entire sites
- Applied declaratively or programmatically
- New controls (more than 50 in all)
- Menus, TreeViews, Wizards, and more
9Theming a Page
lt_at_ Page Theme"BasicBlue"gt
Before
After
10Master Pages
Name Title Microsoft Corporation
11What's New in Security
- Membership service
- Service for managing users and credentials
- Provider-based for flexible data storage
- Login controls
- Controls for logging in, creating new users,
recovering lost passwords, and more - Role Management service
- Combine forms authentication and role-based
authorization without writing code!
12Validating Logins
if (Membership.ValidateUser (UserName.Text,
Password.Text)) RedirectFromLoginPage
(UserName.Text, RememberMe.Checked)
13Validating Logins
If Membership.ValidateUser (UserName.Text,
Password.Text) Then RedirectFromLoginPage
(UserName.Text, RememberMe.Checked) End If
14The Login Control
lthtmlgt ltbodygt ltform runat"server"gt
ltaspLogin RunAt"server" /gt lt/formgt
lt/bodygt lt/htmlgt
15Membership and Logins
Name Title Microsoft Corporation
16Profiles
- Store per-user data persistently
- Strongly typed access (unlike session state)
- On-demand lookup (unlike session state)
- Long-lived (unlike session state)
- Supports authenticated and anonymous users
- Accessed through dynamically compiled
HttpProfileBase derivatives (HttpProfile) - Provider-based for flexible data storage
17Defining a Profile
ltconfigurationgt ltsystem.webgt ltprofilegt
ltpropertiesgt ltadd name"ScreenName" /gt
ltadd name"Posts" type"System.Int32"
defaultValue"0" /gt ltadd name"LastPost"
type"System.DateTime" /gt lt/propertiesgt
lt/profilegt lt/system.webgt lt/configurationgt
18Using a Profile
// Increment the current user's post
count Profile.Posts Profile.Posts 1 //
Update the current user's last post
date Profile.LastPost DateTime.Now
19Using a Profile
' Increment the current user's post
count Profile.Posts Profile.Posts 1 ' Update
the current user's last post date Profile.LastPost
DateTime.Now
20Persisting Data with Profiles
Name Title Microsoft Corporation
21Site Navigation
- Navigation UIs are tedious to implement
- Especially if they rely on client-side script
- New controls simplify site navigation
- TreeView and Menu - Navigation UI
- SiteMapDataSource - XML site maps
- SiteMapPath - "Bread crumb" control
- Public API provides foundation for controls
- Provider-based for flexibility
22Data-Driven Site Navigation
Name Title Microsoft Corporation
23Providers
- New model for storing and managing state
- Makes storage adaptable to different media
- Used by many key ASP.NET services
- Membership service
- Role Management service and more
- Built-in providers make ASP.NET state storage
very flexible - Custom providers make it infinitely flexible
24The Provider Model
Controls
Login
LoginStatus
LoginView
Other Login Controls
Membership API
Membership
MembershipUser
Membership Providers
Other Membership Providers
SqlMembershipProvider
Membership Data
Other Data Stores
SQL Server
25Configuration
- Administrative tools
- ASP.NET MMC snap-in
- Web Site Administration Tool (Webadmin.axd)
- Configuration API
- Read/write access to configuration settings
- Simplified custom configuration sections
- Instrumentation
- Perf counters, health monitoring, and more
26Web Site Administration Tool
Name Title Microsoft Corporation
27Web Parts
- Framework for building portal-style apps
- Patterned after Windows SharePoint Services
- System.Web.UI.WebControls.WebParts
- Rich UIs with minimal code
- Edit page layout using drag-and-drop
- Edit appearance and behavior and more
- Seamless personalization
- Intercommunication ("connections")
28Web Parts
Name Title Microsoft Corporation
29What's New in Localization
- Auto-culture handling
- Declarative mapping of Accept-Language headers to
relevant thread properties - Simplified resource handling
- Declarative mapping of control properties to
resources using lt gt expressions - Strongly typed programmatic resource loading
- ltasplocalize runat"server"gt and more
30What's New in Compilation
- Autocompile anything
- CS files, VB files, RESX files, and so on
- Simply drop files into special directories
- Extensible with custom build providers
- New code-behind model (code-behind 2.0)
- Fixes fragilities in version 1
- Relies on partial class support in compilers
- Precompile and deploy without source
31Dynamic Compilation
vroot
CS
VB
App_Code
Files auto-compiled on first access
WSDL
XSD
App_GlobalResources
RESX
RESOURCE
32Build Providers
- Components that autocompile files
- ltbuildProvidersgt config section maps file types
and directories to build providers
ltcompilation ... gt ltbuildProvidersgt ltadd
extension".resx" appliesTo"Code,Resources"
type"System.Web.Compilation.ResXBuildProvider"
/gt ltadd extension".wsdl" appliesTo"Code"
type"System.Web.Compilation.WsdlBuildProvider"
/gt ltadd extension".xsd" appliesTo"Code"
type"System.Web.Compilation.XsdBuildProvider"
/gt ... lt/buildProvidersgt lt/compilationgt
33Code-Behind 2.0
Hello.aspx
lt_at_ Page CodeFile"Hello.aspx.cs"
Inherits"MyPage_aspx" gt lthtmlgt ltbodygt
ltform runat"server"gt ltaspTextBox
ID"Input" RunAt"server" /gt ltaspButton
Text"Test" OnClick"OnTest" RunAt"server" /gt
ltaspLabel ID"Output" RunAt"server" /gt
lt/formgt lt/bodygt lt/htmlgt
34Code-Behind 2.0
Hello.aspx
lt_at_ Page CodeFile"Hello.aspx.vb"
Inherits"MyPage_aspx" gt lthtmlgt ltbodygt
ltform runat"server"gt ltaspTextBox
ID"Input" RunAt"server" /gt ltaspButton
Text"Test" OnClick"OnTest" RunAt"server" /gt
ltaspLabel ID"Output" RunAt"server" /gt
lt/formgt lt/bodygt lt/htmlgt
35Code-Behind 2.0, Cont.
Hello.aspx.cs
using System public partial class MyPage_aspx
System.Web.UI.Page protected void OnTest
(object sender, EventArgs e)
Output.Text "Hello, " Input.Text
36Code-Behind 2.0, Cont.
Hello.aspx.vb
Imports System Partial Class MyPage_aspx Inherit
s System.Web.UI.Page Protected Sub OnTest
(ByVal sender As Object, ByVal e As EventArgs)
Output.Text "Hello, " Input.Text End
Sub End Class
37Deploying without Source
- Aspnet_compiler.exe precompiles sites and deploys
without source code
38Dynamic Compilation
Name Title Microsoft Corporation
39 Expressions
- Declarative mechanism for loading resources,
connection strings, and more
ASPX
ltaspSqlDataSource ID"Titles" RunAt"server"
ConnectionString"lt ConnectionStringsPubs gt"
SelectCommand"select title_id, title, price
from titles" /gt
Web.config
ltconfigurationgt ltconnectionStringsgt ltadd
name"Pubs" connectionString"serverlocalho
stdatabasepubs..." /gt lt/connectionStringsgt lt/
configurationgt
40Expression Builders
- Components that evaluate expressions
- ltexpressionBuildersgt config section maps prefixes
to expression builders
ltcompilation ... gt ltexpressionBuildersgt
ltadd expressionPrefix"Resources"
type"System.Web.Compilation.ResourceExpressionBui
lder" /gt ltadd expressionPrefix"ConnectionStri
ngs" type"System.Web.Compilation.Connection
StringsExpressionBuilder" /gt ltadd
expressionPrefix"AppSettings"
type"System.Web.Compilation.AppSettingsExpression
Builder" /gt lt/expressionBuildersgt lt/compilationgt
41Custom Expression Builders
Name Title Microsoft Corporation
42Cross-Page Posting
- Pages can now post back to other pages
- Relevant properties
- control.PostBackUrl - Identifies postback target
- Page.PreviousPage - Returns reference to page
that originated a cross-page postback - PreviousPage.IsCrossPagePostBack - Reveals
whether a cross-page postback occurred - _at_ PreviousPageType directive provides strongly
typed access to previous page
43Posting Back to Another Page
lthtmlgt ltbodygt ltform runat"server"gt
ltaspTextBox ID"Input" RunAt"server" /gt
ltaspButton Text"Test" PostBackUrl"PageTwo.aspx"
RunAt"server" /gt lt/formgt lt/bodygt lt/htmlgt
44Referencing a Control on the Previous Page (Weak
Typing)
lthtmlgt ltbodygt ltaspLabel ID"Output"
RunAt"server" /gt lt/bodygt lt/htmlgt ltscript
language"C" runat"server"gt void Page_Load
(Object sender, EventArgs e) if
(PreviousPage ! null PreviousPage.IsCrossPageP
ostBack) TextBox input (TextBox)
PreviousPage.FindControl ("Input")
Output.Text "Hello, " input.Text
lt/scriptgt
45Referencing a Control on the Previous Page (Weak
Typing)
lthtmlgt ltbodygt ltaspLabel ID"Output"
RunAt"server" /gt lt/bodygt lt/htmlgt ltscript
language"VB" runat"server"gt Sub Page_Load
(ByVal sender As Object, ByVal e As EventArgs)
If (PreviousPage ! null And PreviousPage.IsCross
PagePostBack) Then TextBox input
CType(PreviousPage.FindControl("Input"),
TextBox) Output.Text "Hello, "
input.Text End If End Sub lt/scriptgt
46Referencing a Control on the Previous Page
(Strong Typing)
lt_at_ PreviousPageType VirtualPath"/PageOne.aspx"
gt lthtmlgt ltbodygt ltaspLabel ID"Output"
RunAt"server" /gt lt/bodygt lt/htmlgt ltscript
language"C" runat"server"gt void Page_Load
(Object sender, EventArgs e) if
(PreviousPage ! null PreviousPage.IsCrossPageP
ostBack) Output.Text "Hello, "
PreviousPage.InputBox.Text lt/scriptgt
Public property wrapping TextBox
47Referencing a Control on the Previous Page
(Strong Typing)
lt_at_ PreviousPageType VirtualPath"/PageOne.aspx"
gt lthtmlgt ltbodygt ltaspLabel ID"Output"
RunAt"server" /gt lt/bodygt lt/htmlgt ltscript
language"VB" runat"server"gt Sub Page_Load
(ByVal sender As Object, ByVal e As EventArgs)
If (PreviousPage ! null And PreviousPage.IsCross
PagePostBack) Then Output.Text "Hello,
" PreviousPage.InputBox.Text End Sub lt/scriptgt
Public property wrapping TextBox
48Cross-Page Postbacks
Name Title Microsoft Corporation
49Validation Groups
- Validation controls can now be grouped using new
ValidationGroup property - Implemented by validation controls
- Also implemented by Button, LinkButton, and
ImageButton controls - Allows page to post back when validators in
target group are satisfied - Fixes deficiency in ASP.NET 1.x
50Validation Groups
Name Title Microsoft Corporation
51Client Callbacks
- "Lightweight" postbacks
- Client-side callback manager transmits
asynchronous XML-HTTP requests to server - Server receives and processes the request, but
does not rerender the page - Callback manager receives the response and
notifies the client via registered callback - Requires Internet Explorer 5.0 or higher
- Great way to improve UI responsiveness
52How Client Callbacks Work
Client
Server
1
2
Client
Callback Manager
Page
Client initiates callback by calling function
returned by GetCallback-EventReference
Callback manager launches async XML-HTTP call to
server
3
Page's RaiseCall-backEvent method is called
4
5
Callback manager is notified that the call
completed
Client is notified that the call completed and
handed the result
53Client Callbacks
Name Title Microsoft Corporation
54Whos Got the Focus?
- In ASP.NET 1.x, client-side script was needed to
assign focus to a control - In ASP.NET 2.0, use Page.SetFocus
ltaspTextBox ID"UserName" RunAt"server" /gt .
. . ltscript language"C" runat"server"gt void
Page_Load (Object sender, EventArgs e)
SetFocus ("UserName") lt/scriptgt
55Whos Got the Focus?
- In ASP.NET 1.x, client-side script was needed to
assign focus to a control - In ASP.NET 2.0, use Page.SetFocus
ltaspTextBox ID"UserName" RunAt"server" /gt .
. . ltscript language"VB" runat"server"gt Sub
Page_Load (ByVal sender As Object, ByVal e As
EventArgs) SetFocus ("UserName") End
Sub lt/scriptgt
56Panel.DefaultButton
- Designates button to be "clicked" when Enter is
pressed with focus in panel - Work-around for the fact that ASP.NET limits
pages to one runat"server" ltformgt each
ltaspPanel DefaultButton"Button1"
RunAt"server"gt ... ltaspButton
ID"Button1" ... /gt lt/aspPanelgt ltaspPanel
DefaultButton"Button2" RunAt"server"gt ...
ltaspButton ID"Button2" ... /gt lt/aspPanelgt
57URL Mapping
- Maps virtual URLs to physical URLs
- Great for declaratively transforming physical
pages into multiple logical pages
lturlMappings enabled"true"gt ltadd
url"/Home.aspx" mappedUrl"/default.aspx?tabind
ex0" /gt ltadd url"/Forums.aspx"
mappedUrl"/default.aspx?tabindex1" /gt ltadd
url"/Faq.aspx" mappedUrl"/default.aspx?tabinde
x2" /gt lt/urlMappingsgt
Virtual URL
Physical URL
58Machine.config
- Default settings "baked in" to system
- Reduces size of Machine.config
- Improves application startup performance
- New Machine.config-related files
- Machine.config.defaults - Documents default
settings baked into the run-time - Machine.config.comments - Documents syntax of
config elements, many of which are new - Same directory as Machine.config
59(No Transcript)