Web Parts Framework
Creating a Simple Generic Web
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
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
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
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
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” >
<title>Example of a GenericWebPart</title>
cellspacing=”0” cellpadding=”0” border=”0”>
<asp:WebPartZone id= ”MainZone”runat=”server” headertext=”Main”>
<asp:Label id=”contentPart” runat=”server” title=”GenericWebPart”>
<h4>GenericWebPart that uses a label control to generate the contents of
the Web Part
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.
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.
Store user information with a unique user identifier, used to identify the user
when he visits again.
Fetch the user information as needed.
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.
More Related links
This includes introduction of .Net framework, .Net framework architecture, role
of assembly and GAC.
This article explains about authentication, authorization, authentication mode
and impersonation in ASP.NET.
Here you have details about session state, its modes and advantages and
disadvantages of using session state management in ASP.NET.
This is complete article on ADO.NET with code and interview questions
AppSetting section is used to set the user defined values. For e.g.: The
ConnectionString which is used through out the project for database
Following are the major differences between Server.Transfer and
Authentication is the process of verifying the identity of a user.......