Вы находитесь на странице: 1из 2

If you are a veteran ASP/ADO developer who has not tested the .

NET waters, you'd better


get started soon. To give you a taste of .NET, we're going to connect a Microsoft Access
database (you can use a SQL Server or Oracle database instead) to the Internet and then
retrieve and display some data. The example requires both Information Internet Services (IIS)
and the .NET framework. You can download the .NET Framework here. If you want to try a
free ASP.NET development environment, download Web Matrix.

An introduction to server controls


Active Server Pages (ASP) was one of the first Microsoft Web technologies for connecting a
database and the Web. ASP.NET is a complete rewrite of that classic language. You can still
use both, because .NET pages use an .aspx extension. (ASP files keep their .asp extension.)

Much of the code you write in ASP.NET will be executed on the Web server and will return
only HTML to the client. Fortunately, .NET provides you with many new controls that are
similar to standard HTML controls, such as drop-down lists and text boxes. Table A lists the
most common server controls.
Table A
Popular server controls
Control Function
<asp:Button id="button1" Text="Press" runat="server" Creates a standard button on
OnClick="submit"/> the page
<asp:Calendar runat="server" /> Creates a calendar
<asp:DropList id="list1" runat="server"> Creates a drop-down list
<asp:ListBox id="listbox" rows="4" runat="server"> Creates a basic list box
<asp:TextBox id="txtbox" runat="server" /> Creates a standard text box

.NET server controls have the advantage of being created on the Web server as opposed to
being created within the page like HTML. As a result, they're available for processing before
being sent to the client. For example, you can validate content within the page or on the
server side. That means you can validate content within the page and then revalidate content
on the server side.

For the most part, you can create a .NET control simply by adding this component:
runat="server"

to the corresponding HTML element using this syntax:


<asp:control_name id="controlID" runat="server" />

Some development tools are even easier to use. For instance, Visual Studio .NET lets you
create a server control by dragging and dropping the control on a Web page.

In addition to the standard server-side HTML controls, ASP.NET offers a set of validation
controls:

• RequiredFieldValidation requires a value.


• CompareValidator compares the values in two controls, such as validating e-mail
addresses where the user is required to enter an e-mail address twice.
• RangeValidator determines that the entry falls within a set range.
• RegularExpressionValidator validates control entries using regular expressions.
• CustomValidator lets you write your own validation code.
• Validation Summary displays a list showing all the validation currently being used
within a page.

Вам также может понравиться