
C# ПІДРУЧНИКИ / c# / Premier Press - C# Professional Projects
.pdf

BASICS OF ASP.NET WEB APPLICATIONS |
Chapter 19 |
439 |
|||
Table 19-2 Web Form Controls (continued) |
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
Control |
Description |
|
|
|
|
|
|
|
|
|
|
RadioButtonList |
Displays a list of radio buttons that allows users to select one option |
|
|||
|
from list of options. For example, you can use a RadioButtonList control |
|
|||
|
for gender, which displays two check boxes for Male and Female. |
|
|||
Calendar |
Displays a calendar and allows users to select dates and weeks. You can |
|
|||
|
customize the appearance of the calendar to blend it with your Web |
|
|||
|
application. |
|
|
|
|
LinkButton |
A LinkButton control is similar to a Button control but it appears like a |
|
|||
|
hyperlink. |
|
|
|
|
ImageButton |
Displays a button on which you can display an image. |
|
|
|
|
HyperLink |
Used to create hyperlinks from one Web form to another. |
|
|
|
|
Table |
Creates a table and provides several useful methods and properties to |
|
|||
|
render a table from the programming logic of the application. |
|
|||
Panel |
Creates a borderless division on the form that serves as a container for |
|
|||
|
other controls. |
|
|
|
|
Repeater Control |
Displays information from a dataset by using a set of HTML elements |
|
|||
|
and controls.The Repeater control repeats the HTML elements for |
|
|||
|
each record in the data set. |
|
|
|
|
DataList |
Provides extensive layout and formatting options to display information |
|
|||
|
in a table format.This control is similar to a Repeater control but offers |
|
|||
|
greater control over the format of the output. |
|
|
|
|
DataGrid |
The DataGrid control can retrieve information from a dataset and dis - |
|
|||
|
play it directly on a form in the table format without requiring a user to |
|
|||
|
specify the structure of data in the dataset. |
|
|
|
|
|
|
|
|
|
|
ASP.NET provides a number of validation controls that simplify your task of validating user input. Instead of coding validation logic for each control, you can use the validation controls to validate information specified by a user. The validation controls of ASP.NET are summarized in Table 19-3.

440 |
Project 4 |
CREATING AN AIRLINE RESERVATION PORTAL |
||
|
|
|
|
|
|
|
Table 19-3 Validation Controls |
||
|
|
|
|
|
|
|
Control |
Description |
|
|
|
|
|
|
|
|
RequiredFieldValidator |
Ensures that users specify a valid value in the control with |
|
|
|
|
|
which the RequiredFieldValidator control is associated. |
|
|
CompareValidator |
Uses the comparison operators to validate user input with a |
|
|
|
|
|
predefined value of another control or a database field. |
|
|
RangeValidator |
Validates the user input to determine whether or not it is in |
|
|
|
|
|
a predefined range for numbers, characters, or dates. |
|
|
RegularExpressionValidator |
Matches user input with a regular expressions. For example, |
|
|
|
|
|
it checks for predictable sequences of characters, such as |
|
|
|
|
social security numbers, telephone numbers, and zip codes. |
|
|
CustomValidator |
Checks the user’s entry by using validation logic that you |
|
|
|
|
|
code for your application. |
|
|
|
|
|
Working with Web Form Server Controls
Each control has a set of properties that can be used for modifying its state. You can modify the properties of a control at design time or run time.
To modify the properties of a control at design time, follow these steps:
1.Right-click on a control and select Properties. The Properties window for the control will appear. For example, the Properties window of the ListBox control is shown in Figure 19-2.
2.Change the required property of the control. For example, you can change the ID of a list box to lstMonth.

BASICS OF ASP.NET WEB APPLICATIONS |
Chapter 19 |
441 |
|
|
|
|
|
FIGURE 19-2 The Properties window of a control
You can now modify the Items property of the list box to add months to the lstMonth control programmatically. To change the properties of a control at run time, you use the Code Editor window. Use the following steps to open the Code Editor window and change the properties of a control:
1.Drag a Button control from Toolbox to the form.
2.Double-click the button. The Code Editor window will open.
3.Add the following code to the Click event of the button.
private void Button1_Click(object sender, System.EventArgs e)
{
lstMonth.Items.Add(“January”); lstMonth.Items.Add(“February”); lstMonth.Items.Add(“March”); lstMonth.Items.Add(“April”); lstMonth.Items.Add(“May”); lstMonth.Items.Add(“June”);

442 Project 4 CREATING AN AIRLINE RESERVATION PORTAL
lstMonth.Items.Add(“July”);
lstMonth.Items.Add(“August”);
lstMonth.Items.Add(“September”);
lstMonth.Items.Add(“October”);
lstMonth.Items.Add(“November”);
lstMonth.Items.Add(“December”);
}
After specifying the preceding code, when you run the application and click on the button, the list box is populated with the months of the year.
Configuring ASP.NET Applications
After you create an ASP.NET application, you need to secure it. You also need to ensure that your application can be ported to Web ser vers easily. Therefore, two important features of configuring an ASP.NET application are security and deployment. I will include a brief description of these concepts in this section.
Configuring Security for ASP.NET Applications
ASP.NET applications can be secured at IIS or at the Web application level. The security methods employed at these two levels are described in the following list:
IIS. You can configure application-level security to specify the authentication mode for a Web site or a virtual directory at IIS. You can also configure the file access permissions for the Web site on IIS Server.
ASP.NET. All ASP.NET applications include a Web.Config file that is used for storing the application configuration. You can modify this file for changing the authentication mode of your application, specifying a list of users who are allowed to access your Web site, and specifying the default login page that is displayed when an unauthenticated user requests for a resource that requires authentication. The file-based security mechanism provided by ASP.NET can help implement subdirectory level security for a Web application. For example, you can implement form-based authentication for Web forms in one folder of your application, which is accessible to the registered users on the Web site. You can implement Windows authentication for Web forms in another folder, which is accessible only by corporate employees.


444 Project 4 CREATING AN AIRLINE RESERVATION PORTAL
section, I have created a simple application that queries a username and password in a database and displays a welcome message if the user is successfully authenticated.
Creating a New Project
The first step in creating an ASP.NET application in Visual Studio .NET is to add a new project by using the ASP.NET Web Application template. The steps to add a new ASP.NET Web Application were discussed in the section “Summary of Web Form Server Controls.” Create a new project with the name SampleApplication. After creating the new project, proceed to the next section, “Adding Controls to the Project,” to add controls to the sample application.
Adding Controls to the Project
To design the user interface of the application, you need to add controls to the application. The steps to add controls to the Web form are specified in the following list:
1.Click on the View menu and select Toolbox to open Toolbox.
2.Drag a Label control from Toolbox to the default form in the Web application.
3.Change the properties of the label as given here:
ID=lblCaption
Text=Please log on
Font
Bold=True
Italic=True
Name=Georgia
4.Drag two label controls to the form for accepting the username and the password. Change the Text property of these label controls to User Name and Password, respectively.
5.Drag two TextBox controls to the form and change their ID to txtUserName and txtPassword, respectively.
6.Drag a Button control to the form and change its Text property to Submit. In addition, change the ID of the button to btnSubmit.


