Introducing ASP.NET

Introducing ASP.NET

by Anand
Narayanaswamy

ASP.NET (Active Server Pages) is a new and extended technology to the earlier
classic ASP, introduced by Microsoft Corporation, which fully
supports Microsoft’s .NET Framework. It supplies all the required user interfaces under the name "WebForms" and also works
with all .NET
languages like Visual C# .NET, Visual Basic .NET etc. WebForms are used to create user
interfaces for the web pages. Till now, you’ve to apply
specific HTML tags like <Input> and <Select> for creating user interfaces and
ASP
scripting using VBScript or JavaScript. But with the introduction of ASP
.NET, you need  not apply them
any more. All you have to do is to call the custom GUI classes defined in
the System.Web.UI.WebControls namespace of the .NET
Framework. Moreover, System.Web namespace provides necessary
classes, methods and properties for developing client – server applications and System.Web.UI
namespace interacts with other .NET language like C#, VB .NET. Therefore, a C#
file containing some methods or C# syntaxes can be easily called in your ASP applications.    
These topics will be examined in greater detail in the coming sections. 

Benefits of ASP.NET

One major advantage of ASP.NET is that, you can apply the programming
techniques of other .NET languages like C#, 
VB.NET etc. Hence, if you are conversant
with any one language of .NET Framework, then it’ll be easy for you to
write 
ASP.NET programs. Moreover, it eliminates the need for learning complex syntaxes. Another benefit
of ASP.NET is that it supplies built-in controls for validations. Earlier
you’ve
to apply complex
Java Scripts or
VBScripts for validating form elements. Hence, all the essential tools for
developing and deploying ASP applications is now under a single umbrella of
Microsoft .NET. 

Basic requirements for ASP.NET

  1. Microsoft Windows NT Server 4.0, Microsoft Windows 2000, Microsoft
    Windows XP. 
  2. .NET Framework SDK.
  3. Text Editor like Notepad. 
  4. Internet Explorer 5.5 and above.
  5. Visual Studio .NET (Optional, but recommended).

Note: You
have to install Microsoft Data Access Components 2.7
before installing .NET Framework SDK. You can download the same by clicking
here
. Please
go through the additional notes given at the end of this article regarding
Visual Studio .NET. 

There are two phases involved in the
ASP.NET development cycle, which are
a) User Interface phase
b) Coding phase. 
It’s the User Interface phase which we’ll call ‘WebForms’. So, before moving on
to the coding phase, it’s essential for you to be aware of all
types of user interfaces that .NET Framework providesIf
you’re familiar with ‘WinForms’, then you are more likely to confuse it with
WebForms. Keep in mind that WinForms are used to develop standalone GUI
applications (Which can be executed by triggering the relevant .exe file), whereas WebForms are used to create Web based applications like
Java Applets and for creating user interfaces for ASP applications. 

Your First WebForm Program

Copy or enter the following code
in Notepad and save the file as

Firstwebform.aspx
under Inetpub/wwwroot directory:

<form method = "post" runat = "server">
<asp:TextBox runat = "server" ></asp:TextBox>
</form>


If you save the above file in a directory
under the www root, then you’ve to configure for the directory alias using personal web manager.
Please review the additional notes given at the end of this article regarding
configuration of Personal Web Manager. The execution of this file is
very similar to that of classic ASP. Only thing you’ve to remember
is to supply the correct extension for ASP.NET, which is .aspx. 

A WebForm control is created using the following
syntax: 

<form method = "post" runat = "server">
<asp:ControlName runat = "server"></asp:ControlName>
</form>


The runat attribute is
compulsory without which your code will not compile correctly. From the
above code, it can be seen that ASP.NET follows the syntax of XML. 

Working with controls

ASP.NET provides lot of
controls for building powerful user interfaces. Important among them are
Buttons, Radio Buttons, Check Boxes, List Box, Combo Box. The .NET
Framework
also supplies advanced controls like Calendar, AdRotator etc. In the following
sections, Ill cover each of these controls with the help of
simple examples.  

Buttons




Buttons are used to
trigger actions. Without buttons, we cannot do any sort of work on the
form.

<form method = "post" runat = "server">
<asp:Button id = "b1" runat = "server" text = "OK" ToolTip = "Click here">
</asp:Button>
</form>



Radio Buttons





With radio buttons, you can select only one item at a time. Only
thing you’ve to remember is that t
he
GroupName attribute should be same for radiobuttons. 

<form method = "post" runat = "server">
Select your choice: <asp:RadioButton id = "r1" runat = "server" Text = "Male"
GroupName = "g1"></asp:RadioButton>

<asp:RadioButton id = "r2" runat = "server" Text = "Female"
GroupName = "g1"></asp:RadioButton>
</form>

CheckBoxes

Checkboxes enables you to select any number of items at a time. It
can be activated either by clicking on it or by hitting the space
bar.  

<form method = "post" runat = "server">
Choose: <asp:CheckBox id = "c1" runat = "server" Text = "Television"></asp:CheckBox>
<asp:CheckBox id = "c2" runat = "server" Text = "PC" ></asp:CheckBox>
<asp:CheckBox id = "c3" runat = "server" Text = "Telephone" ></asp:CheckBox>
</form>

DropDownList


This control looks like a typical combo box in Visual Basic. Users
can select any one item at a time. 

<form method = "post" runat = "server">
<asp:DropDownList runat = "server">
<asp:ListItem id = "d1" runat = "server" value = "India">India</asp:ListItem>
<asp:ListItem id = "d2" runat = "server" value = "China" >China</asp:ListItem>
<asp:ListItem id = "d3" runat = "server" value = "Russia">Russia</asp:ListItem>
<asp:ListItem id = "d4" runat = "server" value = "USA">USA</asp:ListItem>
<asp:ListItem id = "d5" runat = "server" value = "UK">UK</asp:ListItem>
</asp:DropDownList>
</form>

List Box

With List box, you can select multiple number of items by scrolling
up and down.  

<form method = "post" runat = "server">
<asp:ListBox runat = "server">
<asp:ListItem id = "l1" runat = "server" value = "India">India</asp:ListItem>
<asp:ListItem id = "l2" runat = "server" value = "China" >China</asp:ListItem>
<asp:ListItem id = "l3" runat = "server" value = "Russia">Russia</asp:ListItem>
<asp:ListItem id = "l4" runat = "server" value = "USA">USA</asp:ListItem>
<asp:ListItem id = "l5" runat = "server" value = "UK">UK</asp:ListItem>
</asp:ListBox>
</form>

Image
Button

You
can create a button with an image on it. Try out the following code and
observe the output:

<form method = "post" runat = "server">
<asp:ImageButton id = "b10" runat = "server" src = "f:logo.gif"></asp:ImageButton>
</form>

Calendar 

This
is an advanced control in ASP.NET. Your users can choose a date with the
help of this control. Try out by
copying the following piece of code:  

<form method = post runat = "server">
<asp:Calendar id ="c1" runat = 'server"></asp:Calendar>
</form>

About Visual Studio .NET

Visual
Studio .NET,
shortly VS.NET, provides a very easy way for designing user interfaces using WebForms. You are required to just place the controls from the
Toolbox to the form and set relevant properties form the properties dialog
box, just like Visual Interdev 6.0.
Now Visual Studio .NET provides a single development environment with which you can develop any .NET applications using any
.NET language. In the
earlier version, viz., Visual Studio 6.0, each language had a separate
environment. Hence, developers faced many problems while migrating from one
language to another. They have to understand the new environment and learn new
syntax while migrating from Visual Basic 6.0 to Visual C++ 6.0. These
difficulties are eliminated with the introduction of .NET technology and Visual
Studio .NET. 

 

Configuring
Personal Web Manager

Start
the manager by selecting Start | Programs | Administrative Tools | Personal Web
Manager. If the server has not been started, then click on the start button to
start the same. Click on the Advanced button and click Add button. Type an alias
name and browse for your current folder. Make sure that the execute button is
checked and the directory you created is under the Inetpub/wwwroot
directory.  

Execution URL without creating an
alias                
: http://localhost/Yourfilename.aspx 
Execution URL by creating an alias named ‘internet’: http://localhost/internet/Yourfilename.aspx 
Localhost
can also be substituted with the local IP address 127.0.0.1.  

If Personal Web Manager is not found under the
above mentioned menu, then you’ve to install the same from the control panel. Just follow the steps given
below. 

Click on Start | Settings | Control Panel | Add/Remove Programs | Add/Remove Windows Components and choose Internet Information Services (IIS). Click on the
details button and checkmark Personal Web Manager. 

As a last step, click the Next button. Windows will install the required components. Make sure to insert the Windows 2000 installation
CD, when prompted.

 

Try – Yourself Questions

State whether the following statements are true or false

1) ASP stands for Active Service Pages
2) ASP.NET works under Windows 98 OS. 
3) It’s not neccessary to install Microsoft Data Access Components 2.7, in order
to develop ASP.NET applications. 
4) ASP.NET applications can be developed using Visual Studio 6.0.
5) It’s neccessary to learn XML before learning ASP .NET.
6) Groupname should have to be different for creating radio buttons. 
7) The runat attribute is compulsory in the syntax of a WebForm control. 
8) WebForm and WinForm are not same. If true, point out valid reasons. 
9) "Combobox" control is a valid WebForm control. 
10) Check out the code given below and point out any mistakes: 
      <asp – textbox runat =
server><asp-textbox>

 

About the Author

Anand Narayanaswamy works as a freelance
Web developer, freelance writer, and as an instructor in Thiruvananthapuram, Kerala
State, India. He runs learnxpress.com
and provides free technical support to users worldwide through the site besides
featuring tutorials and articles related to Java, C#, Visual Basic, and other web
technologies like ASP, XML etc. You can browse his online personal site at http://www.learnxpress.com/anandn

More by Author

Must Read