Introduction to ASP.NET 2.0 Web Part Framework
David Barkol Webcast Presenter Neudesic, LLC. http://weblogs.asp.net/davidbarkol
Agenda
Web Part Framework Portals Connecting Web Parts Demos Microsoft® ASP.NET AJAX and Web Parts Resources
Web Parts Framework (1)
Controls
Microsoft® ASP.NET version 2.0 provides three types of controls: custom controls, user controls, and Web Parts Custom controls: Code-intensive way to create components. Shared among projects or sites. User controls: Easier to develop UI. Can’t be shared among projects or Web sites. Can’t inherit from other ASP.NET controls.
Web Parts Framework (2)
Web Parts:
An extension of custom controls with the flexibility and user controls Provide the foundation for both customization and personalization Connections between components
SharePoint and Portals (1)
Windows SharePoint Services
Web Parts first appeared in previous versions of Windows® SharePoint® Services:
Coupled with Microsoft® SQL Server™ and the Active Directory® directory service Could not implement as user control Designed to deal with serialization, storage, and retrieval of customization and personalization data behind the scenes
SharePoint and Portals (2)
Portal Attributes
Common traits of popular portals:
Ability to customize content Ability to personalize content Pageflakes.com, My.Yahoo.com, Google, My.MSN.com, etc. Puts user in control
Sample Portal
Demonstration One
Portals
Web Parts Framework (1)
Key Components
Framework for building portal-style applications
Patterned after Microsoft® Office 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
Personalization capabilities
Web Parts Framework (2)
Key Components
Intercommunication ("connections")
Static – Enables you to declaratively specify the connections in a page Dynamic – Can be created by a user at run time
Scope
Shared – Customization for all users User – Personalization per user
Web Parts Framework (3)
The WebPartManager Control
Orchestrates operation of Web Parts
Maintains list of Web Parts and zones Manages page state (for example, display mode) and fires events when page state changes Facilitates communication between Web Parts Manages personalization
One instance per page; No UI
The WebPartZone Control
Defines zones on a Web Parts page Defines default layout and appearance of Web Parts within each zone
Web Parts Framework (1)
Example of Web Part Zones
Zone #1
Zone #2
Web Parts Framework (2)
Web Parts
Controls defined in a WebPartZone
Web controls, user controls, custom controls
Controls that don't implement IWebPart are internally wrapped in GenericWebParts
Adds properties: Title, Description, etc.
Demonstration Two
Web Part Framework
Web Parts Framework (1)
Display Modes
BrowseDisplayMode DesignDisplayMode EditDisplayMode Standard view mode. No personalization or editing. Enables drag-and-drop layout personalization or customization Enables personalization or customization of Web Part properties to change appearance and behavior. Allows user to delete dynamically added Web Parts. Enables user to connect Web Parts at run time Enables users to add Web Parts at run time
ConnectDisplayMode CatalogDisplayMode
Web Parts Framework (2)
Customization Controls
Controls that are used to customize other controls are called parts
Edit Parts (EditDisplayMode):
PropertyGridEditorPart AppearanceEditorPart BehaviorEditorPart LayoutEditorPart
Catalog Parts (CatalogDisplayMode):
PageCatalogPart – lists of closed Web Parts DeclarativeCatalogPart – lists Web Parts that can be added
Demonstration Three
Customization Controls
Connecting Web Parts (1)
Web Parts can communicate
Provider publishes interface Consumer uses interface to retrieve data
WebPartManager manages connections
Retrieves interfaces from providers Provides interfaces to consumers
Connections can be static or dynamic
ConnectionsZone provides UI for latter
Connecting Web Parts (2)
Connection Providers
Implements Method that returns interface Method attributed [ConnectionProvider]
[ConnectionProvider ("Zip Code", "ZipCodeProvider")] public IZipCode GetZipCodeInterface () { return this; // Assumes control implements IZipCode } // IZipCode.GetZipCode implementation public string GetZipCode () { return _zip; }
Connecting Web Parts (3)
Connection Consumers
Implements Method that receives interface Method attributed [ConnectionConsumer]
[ConnectionConsumer ("Zip Code", "ZipCodeConsumer")] public void GetIZipCodeInterface (IZipCode provider) { string zip = provider.GetZipCode (); // Get zip from provider ... }
Connecting Web Parts (4)
Web Part Connections
1. WebPartManager calls
WebPartManager
[ConnectionProvider] method 2. WebPartManager receives provider interface in return 3. WebPartManager calls [ConnectionConsumer] method, passing interface to consumer 4. Consumer calls provider using supplied interface
Provider
4
Consumer
Demonstration Four
Connecting Web Parts
ASP.NET AJAX and Web Parts
Cross-browser drag-and-drop support Richer user experience Partial-page updates
Demonstration Five
ASP.NET AJAX and Web Parts
Resources
ASP.NET Forums: http://forums.asp.net/145/ShowForum.aspx
ASP.NET 2.0 Web Parts in Action, Darren Neimke, (Manning Publications, 2006) ASP.NET AJAX in Action, Alessandro Gallo, David Barkol, and Rama Vavilala, (Manning Publications, 2007)
www.manning.com david.barkol@neudesic.com http://weblogs.asp.net/davidbarkol
Questions and Answers
Submit text questions using the “Ask” button. Don’t forget to fill out the survey. For upcoming and previously live webcasts:
www.microsoft.com/webcasts
Got webcast content ideas? Contact us at:
http://go.microsoft.com/fwlink/?LinkId=41781
Today's webcast was presented using Microsoft® Office Live Meeting. Get a free 14-day trial by visiting: www.microsoft.com/presentlive