You are on page 1of 20

Introduction to ASP.

NET
ASP.NET is a unified Web development model that includes the services necessary for you
to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the
.NET Framework, and when coding ASP.NET applications you have access to classes in
the .NET Framework. You can code your applications in any language compatible with the
common language runtime (CLR), including Microsoft Visual Basic and C#. These
languages enable you to develop ASP.NET applications that benefit from the common
language runtime, type safety, inheritance, and so on.
ASP.NET is a web application framework developed and marketed by Microsoft to allow
programmers to build dynamic web sites, web applications and web services. It was first
released in January 2002 with version 1.0 of the .NET Framework, and is the successor to
Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common
Language Runtime (CLR), allowing programmers to write ASP.NET code using any
supported .NET language. The ASP.NET SOAP extension framework allows ASP.NET
components to process SOAP messages.

History
After the release of Internet Information Services 4.0 in 1997, Microsoft began researching
possibilities for a new web application model that would solve common complaints about
ASP, especially with regard to separation of presentation and content and being able to write
"clean" code. Mark Anders, a manager on the IIS team, and Scott Guthrie, who had joined
Microsoft in 1997 after graduating from Duke University, were tasked with determining what
that model would look like. The initial design was developed over the course of two months
by Anders and Guthrie, and Guthrie coded the initial prototypes during the Christmas
holidays in 1997.

The initial prototype was called "XSP"; Guthrie explained in a 2007 interview that, "People
would always ask what the X stood for. At the time it really didn't stand for anything. XML
started with that; XSLT started with that. Everything cool seemed to start with an X, so that's
what we originally named it." The initial prototype of XSP was done using Java, but it was
soon decided to build the new platform on top of the Common Language Runtime (CLR), as
it offered an object-oriented programming environment, garbage collection and other features
that were seen as desirable features that Microsoft's Component Object Model platform didn't
support. Guthrie described this decision as a "huge risk", as the success of their new web
development platform would be tied to the success of the CLR, which, like XSP, was still in
the early stages of development, so much so that the XSP team was the first team at
Microsoft to target the CLR.

With the move to the Common Language Runtime, XSP was re-implemented in C# (known
internally as "Project Cool" but kept secret from the public), and the name changed to ASP+,
as by this point the new platform was seen as being the successor to Active Server Pages, and
the intention was to provide an easy migration path for ASP developers.
Mark Anders first demonstrated ASP+ at the ASP Connections conference in Phoenix,
Arizona on May 2, 2000. Demonstrations to the wide public and initial beta release of ASP+
(and the rest of the .NET Framework) came at the 2000 Professional Developers Conference
on July 11, 2000 in Orlando, Florida. During Bill Gates' keynote presentation, Fujitsu
demonstrated ASP+ being used in conjunction with COBOL, and support for a variety of
other languages was announced, including Microsoft's new Visual Basic .NET and C#
languages, as well as Python and Perl support by way of interoperability tools created by
Active State.

Once the ".NET" branding was decided on in the second half of 2000, it was decided to
rename ASP+ to ASP.NET. Mark Anders explained on an appearance on The MSDN Show
that year that, "The .NET initiative is really about a number of factors, it's about delivering
software as a service, it's about XML and web services and really enhancing the Internet in
terms of what it can do ... we really wanted to bring its name more in line with the rest of the
platform pieces that make up the .NET framework."

After four years of development, and a series of beta releases in 2000 and 2001, ASP.NET
1.0 was released on January 5, 2002 as part of version 1.0 of the .NET Framework. Even
prior to the release, dozens of books had been written about ASP.NET, and Microsoft
promoted it heavily as part of their platform for web services. Guthrie became the product
unit manager for ASP.NET, and development continued apace, with version 1.1 being
released on April 24, 2003 as a part of Windows Server 2003. This release focused on
improving ASP.NET's support for mobile devices

Visual Web Developer


Visual Web Developer is a full-featured development environment for creating ASP.NET
Web applications. Visual Web Developer offers you the following features:

* Web page design A powerful Web page editor that includes WYSIWYG editing and
an HTML editing mode with IntelliSense and validation.
* Page design features Consistent site layout with master pages and consistent page
appearance with themes and skins.
* Code editing A code editor that enables you to write code for your dynamic Web
pages in Visual Basic or C#. The code editor includes syntax coloration and IntelliSense.
* Testing and Debugging A local Web server for testing and a debugger that helps you
find errors in your programs.
* Deployment Tools to automate typical tasks for deploying a Web application to a
hosting server or a hosting provider.

ASP.NET Controls
ASP.NET Web server controls are objects on ASP.NET Web pages that run when the page is
requested and that render markup to a browser. Many Web server controls resemble familiar
HTML elements, such as buttons and text boxes. Other controls encompass complex
behavior, such as a calendar controls, and controls that manage data connections.
The topics in this section describe what ASP.NET Web controls are and how to work with
them.

 ASP.NET User Controls

 ASP.NET Web Server Controls

 ASP.NET Web Parts Controls

ASP.NET User Controls


In addition to using Web server controls in your ASP.NET Web pages, you can create your
own custom, reusable controls using the same techniques you use for creating ASP.NET Web
pages. These controls are called user controls.

A user control is a kind of composite control that works much like an ASP.NET Web page—
you can add existing Web server controls and markup to a user control, and define properties
and methods for the control. You can then embed them in ASP.NET Web pages, where they
act as a unit.

At times, you might need functionality in a control that is not provided by the built-in
ASP.NET Web server controls. In those cases, you can create your own controls. You have
two options. You can create:

* User controls. User controls are containers into which you can put markup and Web
server controls. You can then treat the user control as a unit and define properties and
methods for it.
* Custom controls. A custom control is a class that you write that derives from Control
or WebControl.

User controls are substantially easier to create than custom controls, because you can reuse
existing controls. They make it particularly easy to create controls with complex user
interface elements.

User Control Structure

An ASP.NET Web user control is similar to a complete ASP.NET Web page (.aspx file),
with both a user interface page and code. You create the user control in much the same way
you create an ASP.NET page and then add the markup and child controls that you need. A
user control can include code to manipulate its contents like a page can, including performing
tasks such as data binding.

A user controls differs from an ASP.NET Web page in these ways:

* The file name extension for the user control is .ascx.


* Instead of an @ Page directive, the user control contains an @ Control directive that
defines configuration and other properties.
* User controls cannot run as stand-alone files. Instead, you must add them to ASP.NET
pages, as you would any control.
* The user control does not have html, body, or form elements in it. These elements
must be in the hosting page.

You can use the same HTML elements (except the html, body, or form elements) and Web
controls on a user control that you do on an ASP.NET Web page. For example, if you are
creating a user control to use as a toolbar, you can put a series of Button Web server controls
onto the control and create event handlers for the buttons.

ASP.NET Web Server Controls


ASP.NET Web server controls are objects on ASP.NET Web pages that run when the page is
requested and that render markup to the browser. Many Web server controls are similar to
familiar HTML elements, such as buttons and text boxes. Other controls encompass complex
behavior, such as a calendar controls, and controls that you can use to connect to data sources
and display data.

ASP.NET also provides AJAX-enabled server controls. These consist of server and client
code that integrate to produce rich client behavior. When you add an AJAX control to an
ASP.NET Web page, the page automatically sends supporting client script to the browser for
AJAX functionality. You can also provide additional client code to customize the
functionality of a control, but this is not required.

The following are the controls which comes under web server controls:-

 Login Toolbox Controls


 Validation Toolbox Controls
 Data Toolbox Controls
ASP.NET Login Controls
ASP.NET provides robust login (authentication) functionality for ASP.NET Web
applications without requiring programming. The default Visual Studio project templates for
Web applications and for Web sites include prebuilt pages that let users register a new
account, log in, and change their passwords.

You can also create your own pages that you can add ASP.NET login controls to in order to
add login functionality. To use the login controls, you create a Web pages and then add the
login controls to them from the Toolbox.

Typically, you restrict access to ASP.NET pages by putting them into a protected folder. You
then configure the folder to deny access to anonymous users (users who are not logged in)
and to grant access to authenticated (logged-in) users. (The default project template for Web
projects includes a folder named Accounts that is already configured to allow access only to
logged-in users.) Optionally, you can assign users to roles and then authorize users to access
specific Web pages by role.
By default, login controls integrate with ASP.NET membership and ASP.NET forms
authentication to help automate user authentication for a Web site. By default, the ASP.NET
login controls work in plain text over HTTP. If you are concerned about security, use HTTPS
with SSL encryption.

This topic describes each ASP.NET login control This topic contains the following sections:

 The LoginView Control


 The LoginStatus Control
 The LoginName Control
 The PasswordRecovery Control
 The CreateUserWizard Control
 The ChangePassword Control

1. The LoginView Control


The LoginView control allows you to display different information to anonymous and
logged-in users. The control displays one of two templates: the AnonymousTemplate or the
LoggedInTemplate. In the templates, you can add markup and controls that display
information appropriate for anonymous users and authenticated users, respectively.

The LoginView control also includes events for ViewChanging and ViewChanged , which
allow you to write handlers for when the user logs in and changes status.

2. The LoginStatus Control


The LoginStatus control displays a login link for users who are not authenticated and a logout
link for users who are authenticated. The login link takes the user to a login page. The logout
link resets the current user's identity to be an anonymous user.

You can customize the appearance of the LoginStatus control by setting the LoginText and
LoginImageUrl properties.

3. The LoginName Control


The LoginName control displays a user's login name if the user has logged in using
ASP.NET membership. Alternatively, if your site uses integrated Windows authentication,
the control displays the user's Windows account name.

4. The PasswordRecovery Control


The PasswordRecovery control allows user passwords to be retrieved based on the e-mail
address that was used when the account was created. The PasswordRecovery control sends
an e-mail message containing a password to the user.

You can configure ASP.NET membership to store passwords using non-reversible


encryption. In that case, the PasswordRecovery control generates a new password instead of
sending the original password to the user.
You can also configure membership to include a security question that the user must answer
to recover a password. If you do, the PasswordRecovery control asks the question and checks
the answer before recovering the password.

The PasswordRecovery control requires that your application can forward e-mail message to
a Simple Mail Transfer Protocol (SMTP) server. You can customize the text and format of
the e-mail message sent to the user by setting the MailDefinition property.

The following example shows a PasswordRecovery control declared in an ASP.NET page


with MailDefinition property settings to customize the e-mail message.

<asp:PasswordRecovery ID="PasswordRecovery1" Runat="server"


SubmitButtonText="Get Password" SubmitButtonType="Link">
<MailDefinition From="administrator@Contoso.com"
Subject="Your new password"
BodyFileName="PasswordMail.txt" />
</asp:PasswordRecovery>

5. The CreateUserWizard Control


The CreateUserWizard control collects information from potential users. By default, the
CreateUserWizard control adds the new user to the ASP.NET membership system.The
CreateUserWizard control gathers the following user information:

 User name
 Password
 Confirmation of password
 E-mail address
 Security question
 Security answer

The following example shows a typical ASP.NET declaration for the CreateUserWizard
control:

<asp:CreateUserWizard ID="CreateUserWizard1" Runat="server"


ContinueDestinationPageUrl="~/Default.aspx">
<WizardSteps>
<asp:CreateUserWizardStep Runat="server"
Title="Sign Up for Your New Account">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep Runat="server"
Title="Complete">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>

6. The ChangePassword Control


The ChangePassword control allows users to change their password. The user must first
supply the original password and then create and confirm the new password. If the original
password is correct, the user password is changed to the new password. The control also
includes support for sending an e-mail message about the new password.
The ChangePassword control includes two templated views that are displayed to the user.
The first is the ChangePasswordTemplate , which displays the user interface used to gather
the data required to change the user password. The second template is the SuccessTemplate,
which defines the user interface that is displayed after a user password has been successfully
changed.

The ChangePassword control works with authenticated and non-authenticated users. If a user
has not been authenticated, the control prompts the user for a login name. If the user is
authenticated, the control populates the text box with the user's login name.

 
ASP.NET Validation Controls

The RequiredFieldValidator Control


The CompareValidator Control
The RangeValidator Control
The RegularExpressionValidator Control
The CustomValidator Control
The ValidationSummary Control

Validation Server Control Description


RequiredFieldValidator Ensures that the user does not skip a form entry field
CompareValidator Allows for comparisons between the user's input
and another item using a comparison operator
(equals, greater than, less than, and so on)
RangeValidator Checks the user's input based upon a lower- and
upper-level range of numbers or characters
RegularExpressionValidator Checks that the user's entry matches a pattern
defined by a regular expression. This is a good
control to use to check e-mail addresses and phone
numbers
CustomValidator Checks the user's entry using custom-coded
validation logic
ValidationSummary Displays all the error messages from the validators
in one specific spot on the page

Not all button clicks are equal

Normally, in a series of HTML form elements, there is some sort of Button, ImageButton, or
LinkButton control on the page that submits the form and causes the validation to initiate.
This might not be the functionality that you are always looking for in your Web forms. You
may not want each and every button on the ASP.NET page to initiate validation.
For instance, you might have a Cancel or Reset button on the Web page. If the user clicks one
of these buttons, you don't want that button click to validate the contents contained in the
Web form.
To prevent this, you have to set the CausesValidation property for the control to False.
<asp:Button id="Button1" runat="server" Text="Button"
CausesValidation="False"></asp:Button>

1. The RequiredFieldValidator Control


The RequiredFieldValidator server control makes sure that the user enters something into the
field that it is associated with in the form. You need to tie the RequiredFieldValidator to each
control that is a required field in the form. Although this is the simplest of the validation
server controls, you must understand certain things about it.
To see an example of using the RequiredFieldValidator server control, create a Web form
that contains a TextBox server control and a Button server control. Next to the button, place a
RequiredFieldValidator server control.

2. The CompareValidator Control


The CompareValidator server control compares the value entered into the form field to
another field, a database value, or other value that you specify. When comparing against data
types, you just set the Operator—DataTypeCheck. After that is done, you can set the Type
attribute to String, Integer, Double, Date, or Currency in the CompareValidator control to
make sure that the user's input into the field is the specified type.

3. The RangeValidator Control


The RangeValidator server control is similar to the CompareValidator server control, but the
RangeValidator server control compares what is entered into the form field with two values
and makes sure that what was entered by the user is between these two specified values.
For instance, imagine that you have a text box where you want end users to enter their ages.
Instead of being greater than or less than a specific constant, you want the values entered to
be between a specific range of numbers. For this, you use the RangeValidator server control,
as illustrated in Listing 9.
Using the RangeValidator server control to work with a range of numbers
Age:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
&nbsp;
<asp:RangeValidator id="RangeValidator1" runat="server"
ControlToValidate="TextBox1" Type="Integer"
ErrorMessage="You must be between 30 and 40"
MaximumValue="40" MinimumValue="30"></asp:RangeValidator>
In this case, the user should enter a value between 30 and 40 in the text box. If some number
is entered that is outside of this range, the RangeValidator server control fires an error
message and considers the form submission invalid.
The Type property enables you to make comparisons against many different .NET
Framework types, such as String, Integer, Double, Date, and Currency. These choices enable
you to do a number of range comparisons. For instance, you can use the Currency value in
the Type property to retrieve monetary-value entries that are within a certain range. You can
also use the Date value for the Type property to make sure that the entry is between specific
date ranges.
Also, just as you can use the String data type in the CompareValidator server control, you can
use the String data type with the RangeValidator server control to make sure that the value
entered falls within a specific range of characters. For example, if the user is entering her last
name, and you want only people with last names starting with M and P to proceed, you can
easily do this by using the RangeValidator server control, as illustrated in Listing 10.
Comparing an entry to a range of characters
Last name:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
&nbsp;
<asp:RangeValidator id="RangeValidator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="Your last name needs to be between M and P"
MaximumValue="Q" MinimumValue="M"></asp:RangeValidator>
In the example in Listing 10, the value is being checked against a range that is specified by
using the MaximumValue and MinimumValue properties. Notice, in this example, that the
Type property is not specified. In this case, it doesn't need to be specified because the default
value of the Type property is String. If not specified, it is considered to have the value of
String.

4. The RegularExpressionValidator Control


The RegularExpressionValidator server control is a validation control that enables you to
check the user's input based on a pattern defined by a regular expression. This is a great
control to check whether the user has entered a valid e-mail address or telephone number. In
the past, these kinds of validations took a considerable amount of JavaScript coding. The
RegularExpressionValidator control with ASP.NET saves coding time.
In the Properties window for the RegularExpressionValidator server control, click the button
in the ValidationExpression box, and Visual Studio.NET provides you with a short list of
expressions to use in your form via the Regular Expression Editor. However, you are not
limited to these regular expressions in your ASP.NET applications.

5. The CustomValidator Control


You are not limited to the validation controls that have been shown thus far in this article;
you also have the CustomValidator server control. The CustomValidator server control
enables you to develop your own custom server-side or client-side validations. At times, you
may want to compare the user's input to a value in a database, or to determine whether his
input conforms to some arithmetic validation that you are looking for (for instance, if the
number is even or odd). You can do all this and more by using this type of validation control.

6. The ValidationSummary Control


The ValidationSummary server control works with all the validation server controls on the
page. It takes all the error messages that the other validation controls send back to the page
and puts them all in one spot (that you specify) on the page. These error messages can be
displayed in a list, bulleted list, or paragraph.

Showing a Bulleted List of Errors

You can use the ValidationSummary server control in a number of ways, but the example in
Listing 17 shows you how to use it in a simple manner. For this example, two text boxes on
the page are associated with a RequiredFieldValidator control. When an error is triggered, not
only does it display the error next to the text box itself, it also displays it in a summary at the
bottom of the ASP.NET page.
Having a summary of errors appear on the screen
<p>First name
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
&nbsp;
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
runat="server" ErrorMessage="You must enter your first name"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
</p>
<p>Last name
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
&nbsp;
<asp:RequiredFieldValidator id="RequiredFieldValidator2"
runat="server" ErrorMessage="You must enter your last name"
ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server"
Text="Submit"></asp:Button>
</p>
<p>
<asp:ValidationSummary id="ValidationSummary1" runat="server"
HeaderText="You received the following errors:">
</asp:ValidationSummary>
</p>
<p>
<asp:Label id="Label1" runat="server"></asp:Label>
</p>
Using this kind of construct, when the validation server control is triggered, error messages
similar to the ones shown in Figure 9 appear on the screen.
Understanding the Difference Between the ErrorMessage and Text Properties

In the examples shown so far using the ValidationSummary server control, the error
messages were next to the items that were being validated (the RequiredFieldValidator server
controls) and were displayed within the ValidationSummary server control. One ideal way of
presenting this validation-error information is to have an asterisk (*) appear next to the
HTML form fields in question, while the error messages stating what is wrong with the input
appear in the list of errors shown within the ValidationSummary control.

ASP.NET Data Controls


1. Grid view list
A recurring task in software development is to display tabular data. ASP.NET provides a
number of tools for showing tabular data in a grid, including the GridView control. With the
GridView control, you can display, edit, and delete data from many different kinds of data
sources, including databases, XML files, and business objects that expose data.

You can use the GridView control to do the following:

 Automatically bind to and display data from a data source control.


 Select, sort, page through, edit, and delete data from a data source control.

Additionally, you can customize the appearance and behavior of the GridView control by
doing the following:

 Specifying custom columns and styles.


 Utilizing templates to create custom user interface (UI) elements.
 Adding your own code to the functionality of the GridView control by handling
events.

Data Binding with the GridView Control

The GridView control provides you with two options for binding to data:

 Data binding using the DataSourceID property, which allows you to bind the
GridView control to a data source control. This is the recommended approach because
it allows the GridView control to take advantage of the capabilities of the data source
control and provide built-in functionality for sorting, paging, and updating.
 Data binding using the DataSource property, which allows you to bind to various
objects, including ADO.NET datasets and data readers. This approach requires you to
write code for any additional functionality such as sorting, paging, and updating.

When you bind to a data source using the DataSourceID property, the GridView control
supports two-way data binding. In addition to the control displaying returned data, you can
enable the control to automatically support update and delete operations on the bound data.
Formatting Data Display in the GridView Control

You can specify the layout, color, font, and alignment of the GridView control's rows. You
can specify the display of text and data contained in the rows. Additionally, you can specify
whether the data rows are displayed as items, alternating items, selected items, or edit-mode
items. The GridView control also allows you to specify the format of the columns.

2. ListView Control
The ASP.NET ListView control enables you to bind to data items that are returned from a
data source and display them. You can display data in pages. You can display items
individually, or you can group them.

The ListView control displays data in a format that you define by using templates and styles.
It is useful for data in any repeating structure, similar to the DataList and Repeater controls.
However, unlike those controls, with the ListView control you can enable users to edit,
insert, and delete data, and to sort and page data, all without code.

 The following table lists the key classes that are related to the ListView control.

Class Description
A server control that displays the values of a data source by
ListView using user-defined templates. You can configure the control
to enable users to select, sort, delete, edit, and insert records.
ListViewItem An object that represents an item in the ListView control.
An object that represents a data item in the ListView
ListViewDataItem
control.
An enumeration that identifies the function of items in a
ListViewItemType
ListView] control.
A server control that provides paging functionality for
DataPager controls that implement the IPageableItemContainer
interface, such as the ListView
A DataPager field that enables users to select a page of data
NumericPagerField
by page number.
A DataPager field that enables users to move through pages
NextPreviousPagerField of data one page at a time, or to jump to the first or last page
of data.
A DataPager field that enables users to create a custom
TemplatePagerField
paging UI.
3. FormView Control
The FormView control is used to display a single record at a time from a data source. When
you use the FormView control, you create templates to display and edit data-bound values.
The templates contain controls, binding expressions, and formatting that define the look and
functionality of the form. The FormView control is often used in combination with a
GridView control for master/detail scenarios.
The FormView control lets you work with a single record from a data source, similar to the
DetailsView control. The difference between the FormView and the DetailsView controls is
that the DetailsView control uses a tabular layout where each field of the record is displayed
as a row of its own. In contrast, the FormView control does not specify a pre-defined layout
for displaying the record. Instead, you create a template that contains controls to display
individual fields from the record. The template contains the formatting, controls, and binding
expressions used to create the form.

The FormView control is typically used for updating and inserting new records. It is often
used in master/detail scenarios where the selected record of the master control determines the
record to display in the FormView control. For more information and an example, see
Modifying Data Using a FormView Web Server Control.

The FormView control relies on the capabilities of the data source control to perform tasks
such as updating, inserting, and deleting records. The FormView control displays only a
single data record at a time, even if its data source exposes multiple records.

The FormView control can automatically page over the data in its associated data source one
record at a time. This requires that the data is represented by an object that implements the
ICollection interface, or that the underlying data source supports paging. The FormView
control provides the user interface (UI) for navigating between records. To enable paging
behavior, set the AllowPaging property to true and specify a PagerTemplate value.

The FormView control exposes several events that you can handle to execute your own code.
The events are raised before and after insert, update, and delete operations of the associated
data source control. You can also write handlers for the ItemCreated and ItemCommand
events.

4. DetailsView Control
The DetailsView control displays a single record from a data source, where each data row
represents a field in the record. It is often used in combination with a GridView control for
master/detail scenarios.

The DetailsView control gives you the ability to display, edit, insert, or delete a single record
at a time from its associated data source. By default, the DetailsView control displays each
field of a record on its own line. The DetailsView control is typically used for updating and
inserting new records, often in a master/detail scenario where the selected record of the
master control determines the record to display in the DetailsView control. The DetailsView
control displays only a single data record at a time, even if its data source exposes multiple
records.

The DetailsView control relies on the capabilities of the data source control to perform tasks
such as updating, inserting, and deleting records. The DetailsView control does not support
sorting.

The DetailsView control can automatically page over the data in its associated data source,
provided that the data is represented by an object supporting the ICollection interface or that
the underlying data source supports paging. The DetailsView control provides the user
interface (UI) for navigating between data records. To enable paging behavior, set the
AllowPaging property to true.

You select a particular record from the associated data source by paging to that record. The
record displayed by the DetailsView control is the current selected record.

5. DataList Control
The DataList Web server control displays rows of database information in a customizable
format. The format for displaying the data is defined in templates that you create. You can
create templates for items, alternating items, selected items, and edit items. Header, footer,
and separator templates are also available to let you customize the overall appearance of the
DataList. By including Button Web server controls in the templates, you can connect the list
items to code that allows users to switch between display, selection, and editing modes.

The DataList Web server control displays data in a format that you can define using
templates and styles. The DataList control is useful for data in any repeating structure, such
as a table. The DataList control can display rows in different layouts, such as ordering them
in columns or rows.

Optionally, you can configure the DataList control to allow users to edit or delete
information. You can also customize the control to support other functionality, such as
selecting rows.

ASP.NET Web Parts Control


The ASP.NET Web Parts control set is a group of components that work together to enable
you to create Web pages on which end users can modify the appearance and behavior of the
user interface (UI) directly from a browser. This overview covers the fundamental aspects of
the Web Parts control set, including a description of the most frequently used and essential
Web Parts components needed to create a Web Parts page.

 Categories of Web Parts Components

The Web Parts control set consists of three fundamental building blocks: personalization
capabilities, UI structural components required for using Web Parts UI controls on a page,
and the Web Parts UI controls themselves. The following diagram illustrates the relationships
among these building blocks in the Web Parts control set.

Web Parts Essential Controls

The Web Parts control set is extensive, but some controls are essential either because they are
required for Web Parts to work, or because they are the controls most frequently used on
Web Parts pages. As you begin using Web Parts and creating basic Web Parts pages, it is
helpful to be familiar with the essential Web Parts controls described in the following table.

Web Parts control Description


Manages all Web Parts controls on a page. One (and
WebPartManager only one) WebPartManager control is required for
every Web Parts page.
Contains CatalogPart controls. Use this zone to
CatalogZone create a catalog of Web Parts controls from which
users can select controls to add to a page.
Contains EditorPart controls. Use this zone to
EditorZone enable users to edit and personalize Web Parts
controls on a page.
Contains and provides overall layout for the
WebPart controls that compose the main UI of a
WebPartZone page. Use this zone whenever you create pages with
Web Parts controls. Pages can contain one or more
zones.
Contains WebPartConnection controls, and
ConnectionsZone
provides a UI for managing connections..
Renders the primary UI; most Web Parts UI
controls fall into this category.

For maximum programmatic control, you can create


custom Web Parts controls that derive from the base
WebPart control.
WebPart
You can also use existing server controls, user
(GenericWebPart )
controls, or custom controls as Web Parts controls.
Whenever any of these controls are placed in a
zone, the WebPartManager control automatically
wraps them with GenericWebPart controls at run
time so that you can use them with Web Parts
functionality.
Contains a list of available Web Parts controls that
CatalogPart
users can add to the page.
Creates a connection between two Web Parts
controls on a page. The connection defines one of
WebPartConnection
the Web Parts controls as a provider (of data), and
the other as a consumer.
Serves as the base class for the specialized editor
EditorPart
controls.
EditorPart controls

(AppearanceEditorPart, Allow users to personalize various aspects of Web


LayoutEditorPart, BehaviorEditorPart, Parts UI controls on a page.
and PropertyGridEditorPart)

Appearance Editor Part Web Server Control


The AppearanceEditorPart Web server control provides an editor control that enables end
users to edit several user interface (UI) properties on an associated WebPart control.

The AppearanceEditorPart control enables end users to edit several UI properties of a


WebPart control. The following table lists user customizable features and corresponding
WebPart control property values that are editable by using the AppearanceEditorPart control.

User Customizable Feature WebPart Control Property


Set the text for the title. Title
Select the title and border option type. ChromeType
Select the direction that content flows on the page. Direction
Set the height and units. Height
Set the width and units. Width
Hide or show the control. Hidden

To enable editing of other properties and of the behavior of WebPart controls, you can use
the other EditorPart controls supplied with the Web Parts control set. These controls include
the BehaviorEditorPart, the LayoutEditorPart, and the PropertyGridEditorPart controls. The
built-in EditorPart controls provide commonly used editing features for WebPart controls.
You can also create a custom editor control by inheriting from the EditorPart class. For a
code example, see System.Web.UI.WebControls.WebParts..::.EditorPart

BehaviorEditorPart Web Server Control


The BehaviorEditorPart control provides an editor control that enables end users to change
properties that affect the behavior of an associated WebPart or GenericWebPart control.

The BehaviorEditorPart Web server control is an editor part control that enables end users to
change several user interface (UI) properties on an associated WebPart control at run time.
The following table lists user customizable features and the corresponding WebPart control
property values that users can edit by using the BehaviorEditorPart control.

User Customizable Feature WebPart Control Property


 Description
Set the description text of the Web Part.
 TitleUrl
Set the Title link.
 TitleIconImageUrl
Set the Title icon image link.
 CatalogIconImageUrl
Set the Catalog icon image link.
 HelpUrl
Set the Help link.
 Hidden
Hide or show the control.
 HelpMode
Specify the Help mode.
 ExportMode
Select the export mode.
 AuthorizationFilter
Set the authorization filter.
Specify whether a Web part can be removed from the  AllowClose
page.
Specify whether a Web part's properties can be  AllowEdit
edited.
 AllowHide
Specify whether a Web part can be hidden.
 AllowMinimize
Specify whether a Web part can be minimized.
Specify whether a Web part can be moved between  AllowZoneChange
zones, or only within its own zone.

CatalogZone Web Server Control


The CatalogZone control serves as the primary control in the Web Parts control set for
hosting CatalogPart controls on a Web page.

A key feature of Web Parts controls such as the CatalogZone control is that they enable end
users to personalize Web pages and save their personalized settings. The control enables end
users to add WebPart controls or other server controls to a Web Parts page at run time. The
CatalogZone control serves as the primary control in the Web Parts control set for hosting
CatalogPart controls on a Web page.

ConnectionsZone Web Server Control


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
WebPartZoneBase zones.

Using Web Parts controls, you can enable users to create connections at run time between
two server controls to form a connection and share data. One control acts as the provider of
data, and the other control acts as the consumer. The two controls can be WebPart controls or
any other type of server control. They must be designed to handle connections and they must
be in a WebPartZoneBase zone. To learn more about Web Parts connections, see Web Parts
Connections Overview and the WebPartConnection and ConnectionPoint class overviews.

After you have configured the controls to form a Web Parts connection, you must still
connect the controls. 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.

The ConnectionsZone control generates a UI that enables users to connect or disconnect any
eligible controls. It is an optional control that is not necessary to form connections. However,
it is useful when you want to give users control over which server controls are connected or
disconnected.

EditorZone Web Server Control


The EditorZone Web Server control serves as the primary control in the Web Parts control set
for hosting EditorPart controls on a Web page.

A key feature of Web Parts is the ability of end users to personalize Web pages and save their
personalized settings. One aspect of modifying Web Parts pages includes editing the
appearance, layout, behavior, and other properties of the visible WebPart controls.

Several controls in the Web Parts control set provide the editing features. This includes the
EditorZone control, which is the primary control in the Web Parts control set for hosting
EditorPart controls on a Web page.

The following table provides a list of EditorPart controls that the EditorZone can host and a
description of each.

EditorPart Control Description


Lets users customize the visual properties of a WebPart
control at run time, such as the width, height, and title.
AppearanceEditorPart

Lets users customize behavior properties of a WebPart


control at run time, such as displaying minimize, close, and
BehaviorEditorPart
edit buttons.
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
LayoutEditorPart
target zone.

Lets users edit custom properties at run time that are declared
as part of a WebPart control.
PropertyGridEditorPart

WebPartManager Web Server Control


The WebPartManager control is the central control of the Web Parts control set. It manages
all the Web Parts controls, Web Parts functionality, and Web Parts events.

You must add one (but only one) WebPartManager control to every page that uses Web Parts
controls. The WebPartManager control works only with authenticated users.

The following table lists tasks that are performed by the WebPartManager control.

Task Control Functionality


Managing Web Parts Manages the controls on a page that provide Web Parts features.
controls This includes WebPart controls, connections, and zones.
Adding and removing Provides the methods for adding, deleting, and closing WebPart
Web Parts controls controls on a page.
Administering Adds and removes connections between controls. Monitors the
connections connections for problems.
Enables users to move controls on a page, and displays the modes
Personalizing controls and in which users can edit the appearance, properties, and behavior of
pages controls. Maintains user-specific personalization settings on each
page.
Toggling between page Switches between page views, and enables users to carry out tasks
views such as changing page layout or editing controls.
Defines and raises life-cycle events for Web Parts controls,
Raising Web Parts life-
includes events for when controls are added, moved, connected, or
cycle events
deleted.
Exports XML streams that contain the state of the properties of
Enabling import and
WebPart controls, and lets users import the files to personalize
export of controls
controls in other pages or sites.

WebPartZone Web Server Control


The WebPartZone control serves as the primary control in the Web Parts control set for
hosting WebPart controls on a Web page, and provides a common UI for the controls it
contains.

The WebPartZone control inherits user interface elements from the WebZone base class and
provides a common UI for the controls that it contains. These common UI elements are
known collectively as chrome. They consist of the peripheral UI elements on all the controls,
such as the border, title, header and footer, style characteristics, and verbs (UI actions that a
user can carry out on a control, such as close or minimize). For more information about the
UI elements that the WebPartZone control inherits from the WebZone base class, see the
WebZone class documentation.

You might also like