|
Creating Web applications - I
The C# Coumn - Yashawant Kanetkar
The
ASP.NET technology is used to create Web applications and dynamic
websites. ASP.NET is compatible and is integrated with the .NET
environment. It is rather different from ASP. First lets take
a look at what the differences are.
ASP (Active Server Pages) is technology
that enables the dynamic creation of Web pages. An ASP page is an
HTML file with server-side script written in VBScript or JScript.
When a client requests an ASP page, the Web server delivers the
static HTML portions of the page without any modification, and processes
the server-side script, which further generates HTML. The problems
faced with ASP are:
- (a) The scripting is interpreted, leading
to slow rendering of pages.
- (b) The entire HTML portion (content)
and scripting portion (code) is jumbled up in one .asp
file.
- (c) ASP code has to be written for everything,
including simple jobs like validating form fields.
ASP.NET solves all these problems faced
with ASP. First of all, ASP.NET pages are compiled and not interpreted.
Secondly, ASP.NET pages are structured, meaning that server-side
scripts and plain HTML are not jumbled upscripts and HTML can be
separated. ASP.NET provides a feature called code-behind. With this
feature, the server-side code of a page can be separated and placed
into another file. A .aspx file contains the HTML portion
of the application and a .cs file contains the code.
This allows one part of the development team to concentrate on HTML
design, while others work on the code.
Web Forms
.NET Web Applications or Web Forms like WinForms bring the concept
of Rapid Application Development (RAD) to Web application creation.
Web forms are created by dropping controls onto a form and then
double-clicking those controls and writing event handlers for them
in code-behind pages. The controls to be used in Web Forms are present
in the .NET Framework class library. Some controls are mere wrappers
around simple HTML tags, but others represent complex UI objects
that generate HTML. Let us first build a Web Form and then understand
the working of an ASP.NET Web Form application.
In this article, we shall create a registration
form for students to register for an online course. To start with,
create an ASP.NET application named Registration by
selecting ASP.NET Web Application from the template list. On doing
so, a virtual directory named Registration would get created in
the IIS and its local location will be C:\Inetpub\wwwroot\Registration.
As soon as we create a project, the following files would get generated
in the Registration directory:
- A Global.asax file containing application-level
program directives, handlers for application and session-level
events, and declarations of objects that are globally accessible
to all parts of the application.
- A Web.config file containing XML that
stores the application configuration information.
- A WebForm1.aspx file containing HTML
for rendering Web Forms.
- A WebForm1.aspx.cs file containing the
code-behind page written in C#.NET.
- An AssemblyInfo.cs file containing standard
code for assembly description.
- A WebForm1.disco file describing any
Web services in the project.
We will only be concentrating on the WebForm1.aspx
file (content) and the WebForm1.aspx.cs (code) file
for our application.
On creating the application, an empty Web
form gets displayed in the design view of the WebForm1.aspx
file. We intend to add a table to this form. To add a table we need
to select the Table menu and then the Insert | Table
option. We are now presented with the Insert Table Dialog
box. Select the rows (11) and columns (3) that we wish to add to
the table. A grid gets displayed on the form. Insert the controlslabels,
text boxes, validation controls and button to the form as shown
in the following figure.

The details of the controls are given in
the following table.
|
TextBox
TextBox
TextBox
TextBox
TextBox
TextBox
TextBox
TextBox
TextBox
RadioButtonList
Button
|
Uid
Pass
Cpass
Sname
Address
State
Zip
Country
Mail
Course
Submit
|
The controls appearing
in red are called validation controls. Whenever we enter something
on the form and submit it to the server it is called a postback.
Validation controls provide a method of validating user input without
writing any code. Whenever postback is initiated (i.e. we click
the Submit Form button) each control checks the control
it is validating and changes its IsValid property accordingly.
If the property
is set to false, it means that the user input is wrong. In such
a case an error message is flashed. If the property is set to true,
the postback occurs. Some of the validation controls that we have
used in this program are given in the following table.
| RequiredFieldValidator |
Requid |
| CompareValidator |
Compass |
| RegularExpressionValidator |
Checkmail |
The pass textbox
would accept a password. Generally a password is something that
should not be visible, hence we need to change the TextMode property
of this textbox to Password. Now, whatever the student types in,
this textbox is substituted by asterisks (*).
We must now change
the properties of validation controls. But thats for next
time.
 |
Yashavant Kanetkar, one of the first
Express Computer columnists, is an established software expert,
speaker and author with several best-sellers to his credit,
including titles like “Let Us C” and the “Fundas” series. Contact
him at kanet@nagpur.dot.net.in |
|