By Pawan Kapoor, Sumit Goel
(This
paper is a prize winning entry at Literati 2002 )
INTRODUCTION:
ASP stands for
Active Server Pages which run inside
the IIS(Internet Information Server).ASP is a
microsoft technology. To run IIS you must have
window NT4 or later.
An ASP file
name has an extension .asp. It may
contain HTML and coding in languages such as
PERL,J-SCRIPT,VBSCRIPT. Any file with the above
extension is treated as an ASP file by the
windows and it uses ASP engine to execute the
file.
Basic ASP
Syntax
An ASP file can
contains HTML tags, just as a standard HTML file.
In addition , an ASP file can contain server
scripts surrounded by delimiters <% %>.
Server scripts
are executed on the server and can contain any
expression , statement , procedures and operators
valid for the language used for the coding.
ASP: Over
and above HTML
ASP pages score
over normal HTML pages as they can dynamically
edit , add or remove any content of a web page ,
respond to user queries or data submitted from
the HTML forms, access any data from the data
bases and return the results to the browser ,
provide security since the ASP code cannot be
viewed from the browser i.e. when the source of a
web page is viewed the HTML equivalent of the ASP
page is shown and the coding is hidden from the
user . Various sites incorporating dynamic
features are designed using ASP.
Design of
an ASP Page:
An ASP Page may
consists of two parts:
- 1: The
plain HTML: Similar to that in .html
files . This portion of the page is
responsible for the appearance of the
page.
- 2: The
coding part: This part is responsible for
adding dynamic features to the pages and
may contain code in several languages as
PERL,JSCRIPT and VBSCRIPT.
This part
is separated from the HTML part by a set
of delimiters (<% %>).
To Call
an ASP Page:
In order to
execute an ASP page the name of the ASP file is
to be typed in the address bar of the browser as
URL(Unique Resource Locator).
The IIS finds
the page and passes the request to the ASP engine.
The ASP engine reads the FILE line by line, and
executes the scripts in the file. Finally the ASP
file is returned to the browser as Plain HTML.
ASP.NET
AN
INTRODUCTION
ASP.NET is
Microsoft's next generation of Active Server
Pages. It's Microsoft's flagship technology for
building Web sites. You can use ASP.NET to build
large scale commercial Web sites or small company
intranets. The technology was designed to be easy
to use, but very scalable. The ASP.NET files have
an extension as aspx. Declaring an
ASP page file with aspx extension
will make it behave as an ASP.NET page.
ASP.NET over and above ASP
ASP.NET and
Active Server Pages ASP.NET is descended from
Active Server Pages. However, it's such an
evolutionary advance that the two technologies
are only dimly related.
Here are some
of the key benefits of ASP.NET over ASP:
- 1:ASP.NET
Pages are Compiled When an ASP.NET page
is first requested, it is compiled and
cached on the server. This means that an
ASP.NET page executes very quickly.
- 2: ASP.NET
Pages are Built with Server Controls
classes.You can easily build complex Web
pages by assembling the pages out of ASP.NET
server controls. For example, by adding
validation controls to a page, you can
easily validate form data Or, by adding a
DataGrid control to a page, you can
easily display database data.
- 3: Whereas
ASP Classic pages are created with
scripting languages such as VBScript and
JScript, ASP.NET pages are created with
full-blown programming languages such as
Visual Basic (Application, Session, and
Server objectsand C#Request, , there are
over .. And whereas there
are five standard objects available in
the ASP Classic Framework the )Framework
that you can use in an ASPResponse,
3,400 standard objects in the .NET
NET page.
- 4: Browser
Independence: Very often page layouts
of ASP pages needs to be formatted
according to the browser thats
presenting the pages, which often results
in writing different sets of codes for
different browser. This is something any
developer would like to get rid of . CLR(Common
Language Runtime) automatically checks
from the http request headers what
type of browser is making the request and
can generate a page tailored to that
browser. This brings in better browser
compatibility.
Surprisingly,
given all the power and flexibility packed into
ASP.NET. ASP.NET is much easier to use than ASP
Classic. By adding a few server controls to a
page, you can build sophisticated
page in minutes that would take days to develop
with ASP Classic.
DESIGN
OF AN ASP.NET PAGE
ASP.NET
Page typically contains two sections:
- 1:Code
Declaration Block: The code
declaration block contains all the
subroutines and functions that you want
to execute in the page.
- 2:Code
Render Block :The code render block
is executed when the ASP.NET page is
requested and actually rendered to a Web
browser.
For example, the ASP.NET page in Listing
1.0 was written with Visual Basic.
Listing 1.0 -
Simple.aspx
<Script Runat="Server">
Sub Page_Load
myLabel.Text = DateTime.Now()
End Sub
</Script>
<html>
<head><title>Simple.aspx</title></head>
<body>
<asp:Label
ID="myLabel"
Runat="Server" />
</body>
</html>
The Code
Declaration Block:
The code
declaration block in Listing 1.0 is the part of
the page that starts with the <Script Runat="Server">
tag and ends with the closing </Script> tag.
In the listing above, it contains a single
subroutine named Page_Load that executes whenever
the page is requested.The Page_Load subroutine
assigns the current date and time to the Text
property of a Label control.
The Code Render
Block :
The code render
block consists of the remainder of the page below
the code declaration block. You'll notice that
the majority of the code render block is plain
old HTML.
The code render
block contains a single ASP.NET server control.
The Label control is declared with the following
server-side tag:
<asp:Label
ID="myLabel"
Runat="Server" />
ON
LOADING AN ASP PAGE
Whenever an ASP.NET
page is requested, a sequence of events are
raised:
Init - The first event raised when
a page is requested .
Load - This event is raised before
any events are raised by controls contained in
the page.
PreRender - This event is raised
after any events are raised by controls contained
in the page.
UnLoad - This event is raised when
the page is unloaded from memory.
Disposed - This event is raised
when the page is released from memory.
You can create subroutines to handle any of these
events. For example, to handle the Load event,
you would create a subroutine that looks like
this:
<Script Runat="Server">
Sub Page_Load
</Script>
Notice that you handle the page's Load event by
creating a subroutine named Page_Load. You handle
the Init, Load, PreRender, UnLoad, and Disposed
events with Page_Init, Page_Load,
Page_PreRender, Page_UnLoad, and Page_Disposed
subroutines.
By far, the
most useful page event is the Load event.
Typically, you handle this event to assign values
to controls in a page. For example, you would
handle this event to assign a value to a Label
control or assign database data to a DataGrid
control.
Thus each of
these events can be called based upon the demand
of word done by the web-page.
Food
For Thought:The important difference
between the Load and PreRender events is that the
Load event is raised before any events are raised
by controls contained in the page.
For example:If
a .NET page contains a subroutine to handle a
Page Load event, a Button Click event, and a Page
PreRender event. On clicking the button, the
Page_Load subroutine is executed before the
Button_Click subroutine and the Page_PreRender
subroutine is executed after the Button_Click
subroutine.
YOUR
FIRST ASP.NET ASSIGNMENT
Way back when
programming was new, someone decided that the
first thing you should do whenever you start
programming in a new environment or language is
print out "Hello World." I have no idea
who it was that came up with this idea or why it
stuck, but it has. Not being one to fight the
system without reason, we'll be using this
incredibly simple idea as the basis for our first
ASP.NET page. We will consequently discuss
various server controls available in the .NET
through the example.
Lets deal with an HTML page which prints hello
world
helloworld.html
<html>
<
>
<title>ASP.NET Hello World</title>
</head>
<body
bgcolor="#FFFFFF">
<p>Hello World!</p>
</body>
</html>
Now let's try
it in ASP.NET.
Hello
World in ASP.NET
Fundamentally,
there's no requirement that an ASP.NET page (sometimes
referred to as a Web Form) actually do any
processing. As such, the simplest way to get the
task at hand accomplished is to take the existing
HTML page listed above and simply give it an aspx
extension. This results in a perfectly legal and
acceptable ASP.NET page. The only thing that
happens when you do this is that you tell the web
server to pass the aspx file through the ASP.NET
runtime, which in turn compiles it and processes
any code it finds (in this case none) before it
returns the result to the client.
helloworld.aspx
<html>
<head>
<title>ASP.NET Hello World</title>
</head>
<body bgcolor="#FFFFFF">
<p>Hello World!</p>
</body>
</html>
Now move to a version which does some processing:
The Classic ASP
Way One of the nice things about ASP.NET
is that it will work with a lot of classic ASP
style code with only minor changes.
helloworld2.aspx
<%@ Page Language="VB" %>
<html>
<head>
<title>ASP.NET Hello World</title>
</head>
<body bgcolor="#FFFFFF">
<p><%= "Hello World!" %></p>
</body>
</html>
The code listed above probably seemed pretty
familiar to most people, but it illustrates one
of the major limitations of classic ASP scripting.
In order to get the phrase "Hello World!"
in between the two paragraph tags, you had to
place the code that outputs the phrase where you
want the phrase to appear. This makes it
difficult to maintain any sort of structure and
is a chief contributor to much of the so called
"spaghetti code" that developers ended
up writing.
Using
Server Controls - HTML Controls
This time
around, we're going to introduce what is called a
server control. You can think of a server control
as HTML tags for the server. Regular HTML tags
are read by the browser and interpreted in some
way determined by what they contain. The same
happens on the server with server controls, and
the first type of server control, called HTML
Controls, look very much like a standard HTML tag.
The only difference is that they contain a
special runat="server" attribute. You
can see an example illustrated in the code
listing below:
helloworld3.aspx
<%@ Page Language="VB" %>
<%
HelloWorld.InnerText = "Hello World!"
%>
<html>
<head>
<title>ASP.NET Hello World</title>
</head>
<body bgcolor="#FFFFFF">
<p id="HelloWorld" runat="server"></p>
</body>
</html>
Notice how the same <p> tag from our
original document has now become an active part
of the processing of the page. We've given it the
runat="server" attribute which turns it
into a web control. We've also given it an id
attribute so we have a way to reference it
from the code sections of your page. Notice that
the end result of this code is that the section
that actually specifies the text to write out has
been moved into a code section of the page and
this code section can be placed anywhere (ie. not
at the point of display!).
Using Server Controls - Web Controls
Web controls
are the second type of server control. They are
similar to HTML controls, but tend to be more
complex and do not necessarily map directly to
any one HTML tag. This allow them to be much more
flexible and useful. Their object model also is
usually more complex. Where HTML controls tend to
have object models that mirror their HTML tag
counterparts, web controls usually have more
abstract or "high-level" properties and
methods.
helloworld4.aspx
<%@ Page Language="VB" %>
<%
HelloWorld.Text = "Hello World!"
%>
<html>
<head>
<title>ASP.NET Hello World</title>
</head>
<body bgcolor="#FFFFFF">
<p><asp:label id="HelloWorld"
runat="server" /></p>
</body>
</html>
The only thing
that's changed from the previous listing is the
control we're using. We've restored the original
<p> tag so it's now once again a plain old
HTML tag and is entirely ignored by the server
and have placed an <asp:label> tag inside
of it. This new tag is now the focus of our code
that sets the text to "Hello World!".
Notice how the property has changed from
InnerText to simply Text. This is because the
<asp:label> tag object model is defined
differently from that of the HtmlGenericControl
we were using before.
ABSTRACT
In this paper
we will give an insight into a revolutionary
programming framework named as Microsoft.NET
through one of its applications ASP.NET.
The new
platform developed by Microsoft enables rapid
development of powerful web applications and
services which promises to bring revolution in
the present scenario of web programming.
Paper takes a
modular approach to apprehend the above said by
first exploring ASP and then maturing to the
latest .NET platform.
The points of
distinction of .NET and its ASP predecessor are
taken on extensively.
Paper does
equal justice to the much necessary control
classes introduced in the .NET platform as an
unique feature.
The paper
finally concludes with a simple example which
gives enough reason to believe the excellence of
.NET over other platforms by clearly comparing
the features in each of the setups.
CONCLUSION
To conclude ASP.NET
may be truly titled as something which will
redefine web and make web applications faster in
years to come with ease in coding.
Overall the ASP.NET
framework looks very promising .
We feel its
a right opportunity for developers to equip
themselves with this amazing framework.
It provides
minimal learning curve for object oriented
developers and is a powerful framework for
developing and deploying next generation web
applications.
ASP.NET is sure
to have a significant impact on web application
developments in the years to come.
|