C.P. Patel & F.H. Shah Commerce College
C.P. Patel & F.H. Shah Commerce College
What is ASP.Net?
ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web
development platform, which provides a programming model, a comprehensive software infrastructure and
various services required to build up robust web application for PC, as well as mobile devices.ASP.NET is
run inside the IIS(Internet Information Services).
ASP.Net works on top of the HTTP protocol and uses the HTTP commands and policies to set a
browser-to-server two-way communication and cooperation.
ASP.Net is a part of Microsoft .Net platform. ASP.Net applications are complied codes, written
using the extensible and reusable components or objects present in .Net framework. These codes can use the
entire hierarchy of classes in .Net framework.
The ASP.Net application codes could be written in either of the following languages:
C#
Visual Basic .Net
Jscript
J#
ASP.Net is used to produce interactive, data-driven web applications over the internet. It consists of a
large number of controls like text boxes, buttons and labels for assembling, configuring and manipulating
code to create HTML pages.
.Net Framework
1 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
The .NET Framework provides a runtime environment called the Common Language Runtime or
CLR (similar to the Java Virtual Machine or JVM in Java), which handles the execution of code and
provides useful services for the implementation of the program.
The CLR is the execution engine for .NET applications and serves as the interface between .NET
applications and the operating system. The CLR provides many services such as:
It is also known as a base class library. .NET applications, components and controls are built on the
foundation of .NET Framework types .These entities perform the following functions
The .Net Framework class library (FCL) organized in a hierarchical tree structure and it is divided into
Namespaces. Namespaces is a logical grouping of types for the purpose of identification. Framework class
library (FCL) provides the consistent base types that are used across all .NET enabled languages. The
Classes are accessed by namespaces, which reside within Assemblies.
The CLS is a common platform that integrates code and components from multiple .NET
programming languages.
CTS allow programs written in different programming languages to easily share information.
CLS forms a subset of CTS. This implies that all the rules that apply to CTS also apply to CLS also.
It defines rules that a programming language must follow to ensure that objects written in different
programming languages can interact with each other.
CTS provide cross language integration.
The common type system supports two general categories of types:
1. Value Type
2. Reference Type
2 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
Value Type: Stores directly data on stack. In built data type . For ex. Dim a as integer.
Reference Type: Store a reference to the value’s memory address, and are allocated on the heap. For ex:
dim obj as new oledbconnection.
The Common Language Runtime (CLR) can load and execute the source code written in any .Net
language, only if the type is described in the Common Type System (CTS)
When you compile your Visual Basic .NET source code, it is changed to an intermediate language
(IL) that the CLR and all other .NET development environments understand.
All .NET languages compile code to this IL, which is known as Microsoft Intermediate Language,
MSIL, or IL.
MSIL is a common language in the sense that the same programming tasks written with different
.NET languages produce the same IL code.
At the IL level, all .NET code is the same regardless of whether it came from C++ or Visual Basic.
When a compiler produces Microsoft Intermediate Language (MSIL), it also produces Metadata.
The Microsoft Intermediate Language (MSIL) and Metadata are contained in a portable executable
(PE) file .
Microsoft Intermediate Language (MSIL) includes instructions for loading, storing, initializing, and
calling methods on objects, as well as instructions for arithmetic and logical operations, control flow,
direct memory access, exception handling, and other operations
Contents of an Assembly
• Assembly Manifest
• Assembly Name
• Version Information
• Types
• Locale
• Cryptographic Hash
• Security Permissions
3 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
private
shared
Private assemblies Is the assembly which is used by application only, normally it resides in your
application folder directory.
Shared assemblies - It resides in GAC, so that anyone can use this assembly. Public assemblies are always
share the common functionalities with other applications.
It is a central place for registering assemblies, so the different applications on the computer can use it later
on. It is the machine wide code cache in any computer in which CLR is installed
HTML server controls: These are server-based equivalents for standard HTML elements. These controls are
ideal if you’re a seasoned web programmer who prefers to work with familiar HTML tags (at least at first).
They are also useful when migrating ordinary
HTML pages or ASP pages to ASP.NET, because they require the fewest changes.
Web controls: These are similar to the HTML server controls, but they provide a richer object model with a
variety of properties for style and formatting details. They also provide more events and more closely
resemble the controls used for Windows development. Web controls also feature some user interface
elements that have no direct HTML equivalent, such as the GridView, Calendar, and validation controls.
They retain their state: Because the Web is stateless, ordinary web pages need to do a lot of work to store
information between requests. HTML server controls handle this task automatically. For example, if the user
selects an item in a list box, that item remains selected the next time the page is generated. Or, if your code
changes the text in a button,
the new text sticks the next time the page is posted back to the web server.
They fire server-side events: For example, buttons fire an event when clicked, text boxes fire an event when
the text they contain is modified, and so on. Your code can respond to these events, just like ordinary
controls in a Windows application. In ASP code, everything is grouped into one block that executes from
start to finish. With event-based programming, you can easily respond to individual user actions and create
more structured code. If a given event doesn’t occur, the event-handler code won’t be executed.
HTML server controls are ideal when you’re performing a quick translation to add serverside code to an
existing HTML page.
4 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
The ASP.NET Framework contains more than 90 controls. These controls can be divided into seven groups:
Standard Controls— Enable you to render standard form elements such as buttons, input fields, and
labels.
They are server side objects. They are programmable objects that act as user interfaces(UI) elements on
a web page. The class of these controls is System.Web.UI.WebControls.
Syntax:
Validation Controls— Enable you to validate data before you submit the data to the server. For
example, you can use a RequiredFieldValidator control to check whether a user entered a value
for a required input field.
Validation Controls are attached to input controls to test the data the user enters into it. They are used
to test the input.
5 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
Rich Controls— Enable you to render things such as calendars, file upload buttons, rotating banner
advertisements, and multistep wizards.
Data Controls— Enable you to work with data such as database data. For example, you can use these
controls to submit new records to a database table or display a list of database records.
Navigation Controls— Enable you to display standard navigation elements such as menus, tree
views, and bread crumb trails.
Login Controls— Enables you to display login, change password, and registration forms.
HTML Controls— Enable you to convert any HTML tag into a server-side control.
6 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
With the exception of the HTML controls, you declare and use all ASP.NET controls in a page in
exactly the same way. For example, if you want to display a text input field in a page, you can declare a
TextBox control like this:
This section examines ASP.NET pages in more detail. You learn about dynamic compilation and code-
behind files. We also discuss the events supported by the Page class.
When you request an ASP.NET page, ASP.NET Framework checks for a .NET class that corresponds to the
page. If a corresponding class does not exist, the Framework automatically compiles the page into a new
class and stores the compiled class (the assembly) in the Temporary ASP.NET Files folder located at the
following path:
The next time anyone requests the same page in the future, the page is not compiled again. The previously
compiled class is executed, and the results are returned to the browser.
Even if you unplug your web server, move to Borneo for 3 years, and start up your web server again, the
next time someone requests the same page, the page does not need to be recompiled. The compiled class is
preserved in the Temporary ASP.NET Files folder until the source code for your application is modified.
When the class is added to the Temporary ASP.NET Files folder, a file dependency is created between the
class and the original ASP.NET page. If the ASP.NET page is modified in any way, the corresponding .NET
7 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
class is automatically deleted. The next time someone requests the page, the Framework automatically
compiles the modified page source into a new .NET class.
This process is called dynamic compilation, which enables ASP.NET applications to support thousands of
simultaneous users. Unlike an ASP Classic page, for example, an ASP.NET page does not need to be parsed
and compiled every time it is requested. An ASP.NET page is compiled only when an application is
modified.
In a single-file ASP.NET page, a single file contains both the page code and page controls. The page code is
contained in a <script runat="server"> tag.
As an alternative to a single-file ASP.NET page, you can create a two-file ASP.NET page. A two-file
ASP.NET page is normally referred to as a code-behind page. In a code-behind page, the page code is
contained in a separate file.
Page request - When ASP.NET gets a page request, it decides whether to parse and compile the page, or
there would be a cached version of the page; accordingly the response is sent.
Starting of page life cycle - At this stage, the Request and Response objects are set. If the request is an
old request or post back, the IsPostBack property of the page is set to true. The UICulture property of the
page is also set.
Page initialization - At this stage, the controls on the page are assigned unique ID by setting the
UniqueID property and the themes are applied. For a new request, postback data is loaded and the
control properties are restored to the view-state values.
Page load - At this stage, control properties are set using the view state and control state values.
8 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
Validation - Validate method of the validation control is called and on its successful execution, the
IsValid property of the page is set to true.
Postback event handling - If the request is a postback (old request), the related event handler is
invoked.
Page rendering - At this stage, view state for the page and all controls are saved. The page calls the
Render method for each control and the output of rendering is written to the OutputStream class of the
Response property of page.
Unload - The rendered page is sent to the client and page properties, such as Response and Request, are
unloaded and all cleanup done.
The Page class includes a property called the IsPostBack property, which you can use to detect whether the
page has already been posted back to the server.
9 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
Because of View State, when you initialize a control property, you do not want to initialize the property
every time a page loads. Because View State saves the state of control properties across page posts, you
typically initialize a control property only once, when the page first loads.
Many controls don’t work correctly if you reinitialize the properties of the control with each page load. In
these cases, you must use the IsPostBack property to detect whether the page has been posted.
If you need to view detailed error messages when you execute a page, you need to enable debugging for
either the page or your entire application. You can enable debugging for a page by adding a Debug="true"
attribute to the <%@ Page %> directive
Advantages of ASP.NET
To make a clean sweep, with ASP.NET you have the ability to completely separate layout and
business logic. This makes it much easier for teams of programmers and designers to collaborate
efficiently. This makes it much easier for teams of programmers and designers to collaborate
efficiently.
Developer can use VB.NET and access features such as strong typing and object-oriented
programming. Using compiled languages also means that ASP.NET pages do not suffer the
performance penalties associated with interpreted code. ASP.NET pages are precompiled to byte-
code and Just In Time (JIT) compiled when first requested. Subsequent requests are directed to the
fully compiled code, which is cached until the source changes.
The .NET Framework provides class libraries that can be used by your application. Some of the key
classes help you with input/output, access to operating system services, data access, or even
debugging. We will go into more detail on some of them in this module.
Visual Studio .NET provides a very rich development environment for Web
developers. You can drag and drop controls and set properties the way you do in Visual Basic 6. And
you have full IntelliSense support, not only for your code, but also for HTML and XML.
5. State management
To refer to the problems mentioned before, ASP.NET provides solutions for session and application
state management. State information can, for example, be kept in memory or stored in a database. It
10 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
can be shared across Web farms, and state information can be recovered, even if the server fails or
the connection breaks down.
Components of your application can be updated while the server is online and clients are connected.
The Framework will use the new files as soon as they are copied to the application. Removed or old
files that are still in use are kept in memory until the clients have finished.
Configuration settings in ASP.NET are stored in XML files that you can easily read and edit. You
can also easily copy these to another server, along with the other files that comprise your application.
A web server is a computer system that processes requests via HTTP, the basic network
protocol used to distribute information on the World Wide Web. The term can refer to the entire
system, or specifically to the software that accepts and supervises the HTTP requests.
A Web server is a program that uses HTTP (Hypertext Transfer Protocol) to serve the files that
form Web pages to users, in response to their requests, which are forwarded by their
computers' HTTP clients. Dedicated computers and appliances may be referred to as Web
servers as well.
The basic function of a web server is to host websites and to deliver web content from its hosted
websites over the internet. During the delivery of web pages, web servers follow a network
protocol known as hyper text transfer protocol (HTTP).
When you run a web application, Visual Studio starts its integrated web server. Behind
thescenes, ASP.NET compiles the code for your web application, runs your web page, and
thenreturns the final HTML to the browser.
The first time you run a web page, you’ll see a new iconappear in the system tray at the bottom-
right corner of the taskbar. This icon is Visual Studio’stest web server, which runs in the
background hosting your website. The test server only runswhile Visual Studio is running, and it
only accepts requests from your computer (so other userscan’t connect to it over a network).
11 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
When you run a web page, you’ll notice that the URL in the browser includes a port number.For
example, if you run a web application in a folder named OnlineBank, you might see a URLlike
http://localhost:4235/OnlineBank/Default.aspx.
This URL indicates that the web serveris running on your computer (localhost), so its requests
aren’t being sent over the Internet. Italso indicates that all requests are being transmitted to port
number 4235.
That way, the requests won’t conflict with any other applications that might be running on your
computer and listening for requests. Every time Visual Studio starts the integrated web server, it
randomly chooses an available port.
Visual Studio’s built-in web server also allows you to retrieve a listing of all the files in your
website. This means if you create a web application named SampleSite, you can request it inthe
form http://localhost:port/SampleSite (omitting the page name) to see a list of all thefiles in your
web application folder (see Figure 4-21). Then, just click the page you want to test.
There are many types of web servers. Enterprise uses according to their need. Some of the popular category
of web servers are:
HTTP Server: It handles HTTP request coming from client’s browser and transfer the static pages
to client in response to their request. This pages runs on the client browser. It generally contains the
static pages.
FTP Server: These types of servers are used for the transfer from one machine to another using the
internet or intranet. It uses File Transfer Protocol to transfer file from one machine to another. Such
type of server uses some file transfer policies, authentication, login validation etc.
Mail Server: A mail server store and retrieve mail message from client mail box.
Application Server: It is installed database and web servers.
Apache tomcat is popular web server being used today for the implementation of some java
technologies. It is an open source s/w used for implementing web applications.
13 of 14
UM06CBBI57 SERVER SIDE WEB PROGRAMMING UNIT I
Along with the directories you create, ASP.NET also uses a few specialized subdirectories, which it
recognizes by name (see Table 5-2). Keep in mind that you won’t see all these directories in a typical
application. Visual Studio will prompt you to create them as needed.
Directory Description
Bin Contains all the compiled .NET components (DLLs) that the ASP.NET web
application uses. For example, if you develop a custom component for
accessing a database you’ll place the component here. ASP.NET will
automatically detect the assembly, and any page in the web application will be
able to use it.
App_Code Contains source code files that are dynamically compiled for use in your
application. You can use this directory in a similar way as the Bin directory the
only difference is that you place source code files here instead of compiled
assemblies.
App_GlobalResources Stores global resources that are accessible to every page in the web
application. This directory is used in localization scenarios, when you need to
have a website in more than one language. Localization isn’t covered in this
book, although you can refer to Pro ASP.NET 3.5 in VB (Apress, 2007) for
more information.
App_LocalResources Serves the same purpose as App_GlobalResources, except these resources are
accessible to a specific page only.
App_WebReferences Stores references to web services that the web application uses.
App_Data Stores data, including SQL Server 2005 Express Edition database files and
XML files. Of course, you’re free to store data files in other directories.
App_Themes Stores the themes that are used by your web application
.
Disclaimer: The study material is compiled by MR. PREMAL SONI. The basic objective of this material is to
supplement teaching and discussion in the classroom in the subject. Students are required to go for extra reading
in the subject through Library books recommended by Sardar Patel University, VallabhVidyanagar.
14 of 14