Web Parts Framework - ASP.NET

          

Web Parts Framework  ASP.NET


ASP.NET 2.0 Features
Developer Productivity
            Master Pages
            New Code-Behind Model in ASP.NET 2.0
            Creating & Sharing Reusable Components 
            New ASP.NET 2.0 Controls
                       Data Controls
                       Security Controls
                       Other New Controls
                       Validation Groups
            Themes
            Web Parts Framework
            Visual Studio 2005 Improvements
Administration and Management
Speed and Performance
            Caching Feature
ASP.NET 2.0 - Web Parts Framework 

Professional ASP.NET 2.0 Databases

This excerpt from Professional ASP.NET 2.0 Databases   by Thiru Thangarathinam, is printed with permission from
Wrox Publication.
<<Previous  Next>>

Web Parts Framework introduction
Creating a Simple Generic Web Part
Personalization Framework

Web Parts Framework

There are many times when you would want to allow the users of your web site to be able to customize the content by selecting, removing, and rearranging the contents in the web page. Traditionally, implementing this capability required a lot of custom code, or you had to depend on third-party products to accomplish this. To address this shortcoming, ASP.NET 2.0 ships with a Web Parts Framework that provides the infrastructure and the building blocks required for creating modular web pages that can be easily customized by the users. You can use Web Parts to create portal pages that aggregate different types of content, such as static text, links, and content that can change at runtime. It is also possible for the users to change the layout of the Web Parts by dragging and dropping them from one place to another, providing a rich user experience.

By taking advantage of Web Parts, you, as a developer, can empower your users with the ability to perform the following operations.

  • Users can personalize page content.
  • Users can personalize the page layout by allowing the users to drag Web Parts from one zone to another zone, or change its appearance, look and feel, and so on.
  • Users can also export and import Web Part controls so the Web Parts can be effectively shared among other sites.
  • Users can create connections between two Web Parts by establishing communication between Web Part controls.

As a developer, you will typically work with Web Parts in one of the three ways: creating pages that use Web Parts controls, creating individual Web Parts controls, or creating complete personalizable web portals. You can create two kinds of Web Parts in ASP.NET 2.0:

  • Custom Web Part: Those Web Part controls that derive from the System.Web.UI .WebControls.WebParts.WebPart class.
  • Generic Web Part: A custom control that does not inherit from the WebPart class and is still used as a Web Part is called GenericWebPart. For example, if you place a TextBox control inside a WebPartZone control (a zone on the page that hosts the Web Parts control), the TextBox control will be wrapped to a GenericWebPart class.

This section provides you with a simple generic Web Part creation example followed by a code examination. Listing 1-3 shows the code required to implement the Web Part.

Listing 1-3: Creating a Simple Generic Web Part

<%@ Page Language=”C#” %>
<html xmlns=”http://www.w3.org/1999/xhtml” >
      <head runat=”server”>
             <title>Example of a GenericWebPart</title>
      </head>
<body>
          <form id=”form1” runat=”server”>
          <asp:WebPartManager id=”WebPartManager1” runat=”Server”>
          </asp:WebPartManager>
          <table cellspacing=”0” cellpadding=”0” border=”0”>
          <tr>
                 <td valign=”top”>
                 <asp:WebPartZone id= ”MainZone”runat=”server” headertext=”Main”>
                 <ZoneTemplate>
                        <asp:Label id=”contentPart” runat=”server” title=”GenericWebPart”>
                           <h4>GenericWebPart that uses a label control to generate the contents of the Web Part
                           </h4>
                        </asp:Label>
                  </ZoneTemplate>
                  </asp:WebPartZone>
                  </td>
         </tr>
         </table>
         </form>
</body>
</html>

To start with, you declare a WebPartManager control. The WebPartManager control is a must for any ASP.NET page that utilizes Web Parts. This control must be the first element in an ASP.NET web form, above all other Web Parts, zones, or any other custom or specialized Web Part controls. The WebPartManager has no visual element associated with it; however, it is crucial because of the required plumbing it provides for managing the interactions between Web Parts. Then the code declares a WebPartZone control, which in turn includes a Label control that consists of all the HTML elements that make up the display of the Web Part. The WebPartZone control is the one that provides overall layout for the Web Part controls that compose the main UI of a page. Before navigating to the page using the browser, enable Windows Authentication for the web site through IIS Manager and ensure that SQL Server 2005 Express is installed with Windows authentication enabled. Now run the page, and you will see the output shown in Figure 1-2.

ASP.NET 2.0 Web Parts Framework

Personalization Framework

There are times when you want to store and present information that is unique to a specific user. For instance, when a user visits your site, you can collect information from the user about his preferences, such as color scheme, styles, and so forth. Once you have that information, you can use it to present the user with a personalized version of your web application. To implement this with ASP.NET 1.x, you had to go through the following steps.

  1. Store user information with a unique user identifier, used to identify the user when he visits again.
  2. Fetch the user information as needed.
  3. Finally, present the user with the personalized content.

Now with the introduction of ASP.NET 2.0 personalization, all of the above complexities are handled by the personalization framework itself. In ASP.NET personalization, information about a specific user is stored in a persistent format. Also, ASP.NET personalization allows you to easily manage user information without requiring you to create and maintain your own database. In addition, the personalization system makes the user information available using a consistent, easy-to-use, strongly typed API that you can access from anywhere in your application. You can also store objects of any type in the personalization system, including user information, user preferences, or business information. The personalization system uses a generic storage system for storing the data and makes that data available to the users in a type-safe manner. By default, ASP.NET 2.0 uses SQL Server as the storage mechanism.

<<Previous  Next>>



Write your comment - Share Knowledge and Experience


More Related links   

.Net Framework 

This includes introduction of .Net framework, .Net framework architecture, role of assembly and GAC.

ASP.NET Authentication Authorization  

This article explains about authentication, authorization, authentication mode and impersonation in ASP.NET.

ASP.NET Session State Management

Here you have details about session state, its modes and advantages and disadvantages of using session state management in ASP.NET.

ADO.NET

This is complete article on ADO.NET with code and interview questions

What is AppSetting Section in “Web.Config” file? 

AppSetting section is used to set the user defined values. For e.g.: The ConnectionString which is used through out the project for database connection.........

Difference between Server.Transfer and response.Redirect.

Following are the major differences between Server.Transfer and response.Redirect.....

Difference between authentication and authorization.

Authentication is the process of verifying the identity of a user.......

 

Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring