1.36k likes | 1.58k Views
ITEC5620 - Advance Web Programming. Advance Web Programming. อ.ชไลเวท พิพัฒพรรณวงศ์ Chalaivate Pipatpannawong Computer Instructor Microsoft Certificate Professional Web : www.9Expert.co.th ; Thaiwebdev.com E-Mail: chalaivate@chalaivate.com. ปริญญาโท สาขาวิชา เทคโนโลยีสารสนเทศ.
E N D
ITEC5620 - Advance Web Programming Advance Web Programming อ.ชไลเวท พิพัฒพรรณวงศ์ Chalaivate Pipatpannawong Computer Instructor Microsoft Certificate Professional Web : www.9Expert.co.th ; Thaiwebdev.com E-Mail: chalaivate@chalaivate.com ปริญญาโท สาขาวิชา เทคโนโลยีสารสนเทศ
New Features at a Glance Data Controls Login Controls Web Parts Other New Controls Controls Master Pages Themes and Skins Mobility and Localization Compilation Page Framework Membership Role Management Profiles Configuration Services and APIs Site Maps Health Monitoring Other Services
What'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
ASP.NET 1.x Data Binding <asp:DataGrid ID="MyDataGrid" RunAt="server" /> ... <script language="C#" runat="server"> void Page_Load (Object sender, EventArgs e) { SqlConnection connection = new SqlConnection ("server=localhost;database=pubs;integrated security=true"); try { connection.Open (); SqlCommand command = new SqlCommand ("select title_id, titles, price from titles"); MyDataGrid.DataSource = command.ExecuteReader (); MyDataGrid.DataBind (); } finally { connection.Close (); } } </script>
ASP.NET 2.0 Data Binding <asp:SqlDataSource ID="Titles" RunAt="server" ConnectionString="server=localhost; database=pubs;integrated security=true" SelectCommand="select title_id, title, price from titles"/> <asp:DataGrid DataSourceID="Titles" RunAt="server" />
Declarative Data Binding Chalaivate Pipatpannawong Chalaivate.COM
What'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
Theming a Page <%@ Page Theme="BasicBlue"> Before After
Chalaivate Pipatpannawong Computer Instructor www.9Expert.co.th chalaivate@9expert.com
What'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!
Validating Logins if (Membership.ValidateUser (UserName.Text, Password.Text)) RedirectFromLoginPage (UserName.Text, RememberMe.Checked);
The Login Control <html> <body> <form runat="server"> <asp:Login RunAt="server" /> </form> </body> </html>
Membership and Logins Chalaivate Pipatpannawong Computer Instructor www.9Expert.co.th chalaivate@9expert.com
Profiles • 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
Defining a Profile <configuration> <system.web> <profile> <properties> <add name="ScreenName" /> <add name="Posts" type="System.Int32" defaultValue="0" /> <add name="LastPost" type="System.DateTime" /> </properties> </profile> </system.web> </configuration>
Using 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;
Persisting Data with Profiles Chalaivate Pipatpannawong Computer Instructor www.9Expert.co.th chalaivate@9expert.com
Site 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
Data-Driven Site Navigation Chalaivate Pipatpannawong Computer Instructor www.9Expert.co.th chalaivate@9expert.com
Providers • 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
The Provider Model Controls Login LoginStatus LoginView Other Login Controls Membership API Membership MembershipUser Membership Providers AccessMembershipProvider SqlMembershipProvider Other Membership Providers Membership Data Access SQL Server Other Data Stores
Configuration • 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
Web Site Administration Tool Chalaivate Pipatpannawong Chalaivate.COM
Web Parts • Framework for building portal-style apps • Patterned after SharePoint Portal Server • 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")
Web Parts Chalaivate Pipatpannawong Chalaivate.COM
What's New in Mobility • Unified Control Architecture • Adapters enable pages and controls to render markup for different device types • WML adapters provided by third parties • Device filters <asp:Label Text="Hello, world" RunAt="server" Nokia:Text="Hello, Nokia" Up:Text="Hello, OpenWave" /> OpenWave browsers Nokia browsers
What'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 <%$ … %> expressions • Strongly typed programmatic resource loading • <asp:localize runat="server"> and more
What'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
Dynamic Compilation vroot CS VB Code Files auto-compiled on first access WSDL XSD Resources RESX RESOURCE
Build Providers • Components that autocompile files • <buildProviders> config section maps file types and directories to build providers <compilation ... > <buildProviders> <add extension=".resx" appliesTo="Code,Resources" type="System.Web.Compilation.ResXBuildProvider"/> <add extension=".wsdl" appliesTo="Code" type="System.Web.Compilation.WsdlBuildProvider"/> <add extension=".xsd" appliesTo="Code" type="System.Web.Compilation.XsdBuildProvider"/> ... </buildProviders> </compilation>
Code-Behind 2.0 Hello.aspx <%@ Page CompileWith="Hello.aspx.cs" ClassName="MyPage_aspx" %> <html> <body> <form runat="server"> <asp:TextBox ID="Input" RunAt="server" /> <asp:Button Text="Test" OnClick="OnTest" RunAt="server" /> <asp:Label ID="Output" RunAt="server" /> </form> </body> </html>
Code-Behind 2.0, Cont. Hello.aspx.cs using System; partial class MyPage_aspx { void OnTest (Object sender, EventArgs e) { Output.Text = "Hello, " + Input.Text; } }
Precompilation • Precompile.axd precompiles sites in place to avoid first-access delays
Deploying without Source • Aspnet_compiler.exe precompiles sites and deploys without source code
Dynamic Compilation Chalaivate Pipatpannawong Computer Instructor www.9Expert.co.th chalaivate@9expert.com
$ Expressions • Declarative mechanism for loading resources, connection strings, and more ASPX <asp:SqlDataSource ID="Titles" RunAt="server" ConnectionString="<%$ ConnectionStrings:Pubs %>" SelectCommand="select title_id, title, price from titles" /> Web.config <configuration> <connectionStrings> <add name="Pubs" connectionString="server=localhost;database=pubs;..." /> </connectionStrings> </configuration>
Expression Builders • Components that evaluate $ expressions • <expressionBuilders> config section maps prefixes to expression builders <compilation ... > <expressionBuilders> <add expressionPrefix="Resources" type="System.Web.Compilation.ResourceExpressionBuilder" /> <add expressionPrefix="ConnectionStrings" type="System.Web.Compilation.ConnectionStringsExpressionBuilder" /> <add expressionPrefix="AppSettings" type="System.Web.Compilation.AppSettingsExpressionBuilder" /> </expressionBuilders> </compilation>
Custom Expression Builders Chalaivate Pipatpannawong Computer Instructor www.9Expert.co.th chalaivate@9expert.com
Cross-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 • @ PreviousPageType directive provides strongly typed access to previous page
Posting Back to Another Page <html> <body> <form runat="server"> <asp:TextBox ID="Input" RunAt="server" /> <asp:Button Text="Test" PostBackUrl= "PageTwo.aspx" RunAt="server" /> </form> </body> </html>
Referencing a Control on the Previous Page (Weak Typing) <html> <body> <asp:Label ID="Output" RunAt="server" /> </body> </html> <script language="C#" runat="server"> void Page_Load (Object sender, EventArgs e) { if (PreviousPage != null && PreviousPage.IsCrossPagePostBack) { TextBox input = (TextBox) PreviousPage.FindControl ("Input"); Output.Text = "Hello, " + input.Text; } } </script>
Referencing a Control on the Previous Page (Strong Typing) <%@ PreviousPageType VirtualPath="~/PageOne.aspx" %> <html> <body> <asp:Label ID="Output" RunAt="server" /> </body> </html> <script language="C#" runat="server"> void Page_Load (Object sender, EventArgs e) { if (PreviousPage != null && PreviousPage.IsCrossPagePostBack) Output.Text = "Hello, " + PreviousPage.InputBox.Text; } </script> Public property wrapping TextBox
Cross-Page Postbacks Chalaivate Pipatpannawong Chalaivate.COM
Validation 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
Validation Groups Chalaivate Pipatpannawong Computer Instructor www.9Expert.co.th chalaivate@9expert.com
Client 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
How 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 5 4 Client is notified that the call completed and handed the result Callback manager is notified that the call completed
Client Callbacks Chalaivate Pipatpannawong Computer Instructor www.9Expert.co.th chalaivate@9expert.com
Who's 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 <asp:TextBox ID="UserName" RunAt="server" /> . . . <script language="C#" runat="server"> void Page_Load (Object sender, EventArgs e) { SetFocus ("UserName"); } </script>