Using Web Parts in ASP.Net 2.0
in ASP.Net 2.0 are used to customize the web applications. A web page
is divided into different areas and each area could be a web part that
can customized according to the users preference.
To include WebParts in a web page, you need to have one WebPartManager control in that page. Only one WebPartManager control is necessary to control all the WebParts in a particular page. The WebParts in a page can further be divided into WebPartZones each of which can display different contents. Optionally a WebZone can have CatalogZone control, which is used to display the catalogs of WebParts. The following code displays the WebPartManager control and a WebPartZone in a web page.
When the DisplayMode property of the WebPartManager is set to CatalogDisplayMode, you can add WebParts to the page. The CatalogZone control displays the Page Catalog and Declarative Catalog. The DeclarativeCatalogPart in the CatalogZone displays all the web controls to be displayed. These web controls are held in the WebPartsTemplate. The code listing given above gives a clear picture of the hierarchy of the web part controls in a web page.
Within the WebPartsTemplate, you can display the content that is needed for the parts. You can create your own web parts that are to be displayed. We will consider a case, where you need to display the list of employees in a particular department of an organization. This data needs to be displayed within a WebPart in a web page. To do this, you have to perform the following steps:
the System.Web.UI.WebControls.WebParts namespace.
Using the above steps, you can create a custom WebPart named DeptEmployees and you can display it using the following tag, within the CatalogZone.
<custom:DeptEmployees ID="myDeptEmp" Runat="Server" />
Once you have the web part in a page, you can add the web part from the declarative catalog to the web part zones using the ADD button in the declarative catalog zone. A web part thus added to a web part zone can be moved to any web part zone, by simply dragging the web part to that particular zone.
As you know that web parts are different areas of a web page that can be customized, you can also build more complex web parts that can be customized by the user who is using the web page. It is also possible to share information between different web parts. For example, you can create web parts so that when you select the department information from a drop down list in a web part, that data is transferred to another web part so that the other web part displays all the employees of the selected department. Thus connections between web parts can be static or dynamic. Static connections are created when you code the web parts and dynamic connections are created by the user at runtime. It is also possible to use the same web parts in different web applications and different web sites by exporting and importing the web parts.