Professional Documents
Culture Documents
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
* 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.
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.
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.
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 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:-
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 also includes events for ViewChanging and ViewChanged , which
allow you to write handlers for when the user logs in and changes status.
You can customize the appearance of the LoginStatus control by setting the LoginText and
LoginImageUrl properties.
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.
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:
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
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>
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>
<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>
<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.
Additionally, you can customize the appearance and behavior of the GridView control by
doing the following:
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.
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.
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.
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
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.
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.
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:
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.
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.
Lets users edit custom properties at run time that are declared
as part of a WebPart control.
PropertyGridEditorPart
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.
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.