2. Agenda 1 Introduction 2. Before webpart 3. Need of webpart 4. Web part benefits 5. Dev environment required for web parts 6. Web part infrastructure 7. Hello world web part 8. Getting property from editor zone 9. Calling web service from web part 10. Showcase Data grid in web part 11. Using ajax in webpart 12. Using user control in web part 13. Best coding practices for web part
5. Introduction A Web Part is a .NET Web custom control assembly that uses a Web Part description file (.dwp). The .dwp file contains XML metadata that describes an instance of the Web Part. Web Parts is a framework built into ASP.NET 2.0 for building highly customizable portal-style pages.
6. Introduction ASP.NET Web parts is an integrated set of controls for creating Web sites that enable end users to modify the content, appearance, and behavior of Web pages directly from a browser. End users can customize Web Parts pages by changing the page layout, adding and removing Web Parts, editing Web Parts properties, establishing connections between Web Parts, and more.
7. Before Web Parts….. Before ASP.NET 2.0, developer had to build his own custom personalization framework to implement personalization feature in the application. Web Parts are included in ASP.NET server control framework and are used like any other ASP.NET server controls.
8. Building Web Parts There are two basic ways to create a Web Part. You can treat any standard Microsoft ASP.NET control as a Web Part or you can build a custom control that derives from the base WebPart class.You are not required to modify a control in any way to use it as a Web Part. Standard ASP.NET controls (such as the Calendar and GridView controls), Web User Controls, and even custom controls can all be used as Web Parts.
9. One of the simplest ways to use controls is through the Visual Studio development environment. The Toolbox area within Visual Studio (when developing Web Forms) includes a Web Parts category that contains the various controls available to utilize Web Parts in an application.
12. InitializationThe WebPartZone objects register with the WebPartManager control.The WebPartManager control loads the static WebPart objects.The WebPartManager control calls the TrackViewState method for each static WebPart object already in the control hierarchy at this point. Initialization CompleteThe WebPartManager control loads the dynamic WebPart objects and the WebPartConnection objects. The WebPartManager control calls the WebPartPersonalization control on the static and dynamic WebPart objects.
13. Load CompleteThe WebPartManager control activates the WebPartConnection objects. Save State Complete The WebPartManager control saves the static and dynamic WebPart objects' personalization information in permanent storage.
15. Advantages of Web Parts Web Parts allows for personalization of page content. They allows users to move or hide the Web Parts and add new Web Parts changing the page layout. Web Parts allows user to export or import Web Parts settings for use in other pages. Web Parts retain the properties, appearance and the data across the pages when imported or exported. Web Parts can be assigned role-based access. So you can determine which Web Parts can share by all or which should be hidden for certain roles. This helps us to provide customized content based on security. Web Parts can talk to each other. You can utilize the data in one Web Part in another Web Part for different purposes.
16. Web Parts Modes a) Normal mode: End user cannot edit or move sections of page. b) Edit Mode: End user can edit Web Parts on the page including Web Parts title, color or even setting custom properties. c) Design Mode: End user can rearrange the order of the pages Web Parts in a WebPartZone. d) Catalog Mode: End user enjoys the choice to add new Web Parts or add deleted Web Parts in any WebPartZone on the page.
17. WebPartManager The WebPartManager is the manager for all web parts. If you use webparts in your web projects you are required to use the WebPartManager. Usually you just drag and drop this into your webform and are ready to go. WebPart Zones There are four kinds of zones in web part zones: Web Part Zone Editor Zone Catalog Zone Connection Zone WebPart Zone The web part Zone is the basic unit for web parts. By placing different contents in a web part zone we can allow a user to drag and drop contents on a page.
18. Catalog Zone The purpose of the CatalogZone control is to allow end users to customize Web Parts pages by adding Web Parts to them. for example, to enable users to restore closed Web Parts to the page by including a CatalogZone in the page. A Catalog Zone can contain several types of Catalog Part controls. The following list summarizes the Catalog Part controls provided with the Web Parts control set: PageCatalogPart DeclarativeCatalogPart ImportCatalogPart
19. EditorZone The EditorZone Web Server control serves as the primary control in the Web Parts control set for hosting EditorPart controls on a Web page. AppearanceEditorPart:- Lets users customize the visual properties of a WebPart control at run time, such as the width, height, and title. BehaviorEditorPart:- Lets users customize behavior properties of a WebPart control at run time, such as displaying minimize, close, and edit buttons.
20. LayoutEditorPart:- Lets users customize layout properties of a WebPart control at run time, such as selecting a minimized or normal state, or setting the index at which the control will appear within the target zone. PropertyGridEditorPart:- Lets users edit custom properties at run time that are declared as part of a WebPart control.
21. Following is the list of features provided exclusively by the SharePoint WebPart class: Cross page connections Connections between Web Parts that are outside of a Web Part zone Client-side connections (Web Part Page Services Component) A data caching infrastructure that allows caching to the content database
22. User Control Vs Web Parts User Control User Controls cannot be shared across web applications but they can be created using a designer tool. Customization and personalization is not possible using User Controls. Web Part Web Part is a combination of User Control and Custom Control. Web Parts are ASP.NET controls in that they add extra dimensions of user customization and personalization.
23. Simple Hello World Example for Web Parts Visual studio ->create web Site ->asp.net web site ->ok
42. The code will populate the DropDownList with all the available modes for the WebParts. private void BindData() { WebPartDisplayModeCollection modes = wpm.DisplayModes; foreach (WebPartDisplayMode mode in modes) { ddlModes.Items.Add(mode.Name); } ddlModes.DataBind(); }
43. Now, in order to select the particular mode you need to catch the Selected_IndexChanged event of the DropDownList. protected void ddlModes_SelectedIndexChanged(object sender, EventArgs e) { WebPartDisplayMode mode = (WebPartDisplayMode) wpm.SupportedDisplayModes[ddlModes.SelectedValue]; wpm.DisplayMode = mode; }
61. Connection Zone The ConnectionsZone Web server control provides a user interface (UI) that enables users to form connections between WebPart and other server controls that reside in WebPartZoneBasezones. You can connect controls in these ways: Declare a connection in a Web page. Create a connection in code. Add a ConnectionsZone control to the page so that users can connect the controls on demand.