Skip to document
University
High School
Sign in
My Library
Information
AI Chat
Chapter 5 of pt
chapter 5
Course
Programming Technology (CMP 211)
35 Documents
University
Pokhara University
Academic year: 2024/2025
Uploaded by:
Sandesh Lamsal
Gandaki Boarding School
0followers
4Uploads0upvotes
Follow
Recommended for you
14
java assignment
Programming Technology
Tutorial work
100%(3)
18
Programming - Old Question Collection of P-T BE Computer - IV
Programming Technology
Other
100%(2)
10
Aptassign - Summary Programming Technology
Programming Technology
Summaries
100%(1)
Comments
Please sign in or register to post comments.
Report Document
Students also viewed
Chapter 3 of pt
Chapter 4 of pt
Chapter 2 of pt
Pt ch 1
Java Note - 2023.04.25 - Continue
Chapter 1
Related documents
Chapter 3 - jf7t9kbj
Chapter 5 - hjyhog
Chapter2: Second
CH4
CH3 - Programming Technology - PoU
CH2 - Programming Technology - PoU
Preview text
Chapter 5: Web and Database programming with .NET [Credit: 3 hrs]
5. Active Server Pages (ASP)
ASP (aka Classic ASP) was introduced in 1998 as Microsoft's first server side scripting
language.
Classic ASP pages have the file extension .asp and are normally written in VBScript.
Active Server Pages (ASP) is a server-side scripting technology that can be used to create dynamic
and interactive Web applications. An ASP page is an HTML page that contains server-side scripts
that
are processed by the Web server before being sent to the user's browser. We can combine
ASP with
Extensible Markup Language (XML), Component Object Model (COM), and Hypertext Markup
Language (HTML) to create powerful interactive Web sites.
Server-side scripts run when a browser requests an .asp file from the Web server. ASP is called by
the Web server, which processes the requested file from top to bottom and executes any script
commands. It then formats a standard Web page and sends it to the browser.
An example of classical asp page saved with .asp extension: This example displays the words
"Hello
World" when run with Internet Information Services (IIS) server.
<%@ Language=VBScript %>
<html> <head> <title>Example 1</title> </head>
<body>
<% FirstVar = "Hello world!" %>
<%=FirstVar%>
</body>
</html>
For IIS installation; Reference Video itnota/installyoutube/watch?v=nkus5mXuaFo-iis-windows/
5. ASP
ASP was released in 2002 as a successor to Classic ASP. ASP pages have the
extension .aspx and are normally written in C# (C sharp). ASP 4 is the latest official version of
ASP.
ASP is a web development platform provided by Microsoft. It is used for creating web-based
applications.
The first version of ASP deployed was 1. The most recent version of ASP is version 4.
ASP is designed to work with the HTTP protocol. This is the standard protocol used across all
web applications.
ASP applications can also be written in a variety of .Net languages. These include C#, VB,
and J#.
Difference between ASP and ASP:
S. ASP ASP
1 ASP is the interpreted language. ASP is the compiled language.
2 ASP uses ADO (ActiveX Data Objects)
technology to connect and work with
databases.
ASP uses ADO to connect and work
with database.
3 ASP is partially object oriented. ASP is fully object oriented.
S. ASP ASP
4 ASP Pages have the file
extension .asp.
ASP Pages have the file extension .aspx.
5 ASP doesn’t have the concept of
inheritance.
ASP inherits the class written in code behind.
6 ASP pages use scripting language. ASP use full-fledged programming language.
7 Error handling is very poor in ASP. Error handling is very good in ASP.
8 ASP has maximum four in-built
classes i. Request, Response,
Session and Application.
ASP has more than 2000 in-built classes.
ASP Architecture and its Components
ASP is a framework which is used to develop a Web-based application. The basic
architecture of
the ASP framework is as shown below.
Fig: ASP Architecture Diagram
The architecture of the framework is based on the following key components
1. Language – A variety of languages exists for .net framework. They are VB and C#. These
can be used to develop web applications.
2. Library - The .NET Framework includes a set of standard class libraries. The most common
library used for web applications in .net is the Web library. The web library has all the
necessary components used to develop web-based applications.
3. Common Language Runtime - The Common Language Infrastructure or CLI is a platform.
.Net programs are executed on this platform. The CLR is used for performing key activities.
Activities include Exception handling and Garbage collection.
Seven key pillars of ASP
1. ASP is integrated with the .NET Framework
The .NET Framework is divided into an almost painstaking collection of functional parts, with
tens of thousands of types (the .NET term for classes, structures, interfaces, and other core
programming ingredients).
2. ASP is Compiled, Not Interpreted
ASP applications, like all .NET applications, are always compiled. In fact, it’s impossible to
execute C# or Visual Basic code without it being compiled first.
App_GlobalResources contains global resources that are accessible to every page in the web
application.
App_LocalResources serves the same purpose as app_globalresources, except that these
resources are accessible to a specific page only.
App_WebReferences stores references to web services that the web application uses. These
references can be remote code routines that a web application can call over
a network/Internet.
App_Data Stores data, including SQL Server Express database files, mdf files, xml file
and so on.
App_Themes contains collection of files like .skin and .css files that are used for
application look and feel appearance.
Bin contains all the precompiled .Net assemblies like DLLs that the ASP
web application uses.
Compilation of ASP webpage
ASP applications, like all .NET applications, are always compiled. In fact, it’s impossible to
execute C# or Visual Basic code without it being compiled first. .NET applications actually go
through
two stages of compilation.
In the first stage, the C# code is compiled into an intermediate language called Microsoft
Intermediate
Language (MSIL), or just IL. This first step is the fundamental reason that .NET can be
language-
interdependent. Essentially, all .NET languages (including C#, Visual Basic, and many more)
are
compiled into virtually identical IL code. This first compilation step may happen automatically
when the
page is first requested. The compiled file with IL code is an assembly.
The second level of compilation happens just before the page is actually executed. At this
point, the IL
code is compiled into low-level native machine code. This stage is known as just in time (JIT)
compilation, and it takes place in the same way for all .NET applications (including Windows
Applications, for example). Figure below shows this two-step compilation process. .NET
compilation is
decoupled into two steps in order to offer developers the most convenience and the best
portability.
Before a compiler can create low-level machine code, it needs to know what type of operating
system
and hardware platform the application will run on (for example, 32-bit or 64-bit Windows). By
having
two compile stages, we can create a compiled assembly with .NET code and still distribute
this to
more than one platform.
####### Fig: Compilation of asp web page
JIT compilation probably wouldn’t be that useful if it needed to be performed every time a
user
requested a web page from our site. Fortunately, ASP applications don’t need to be compiled
every time a web page is requested. Instead, the IL code is created once and regenerated
only when
the source is modified. Similarly, the native machine code files are cached in a system
directory that
has a path.
5. ASP page life cycle.
When a page is requested, it is loaded into the server memory, processed, and sent to the
browser.
Then it is unloaded from the memory. At each of these steps, methods and events are
available,
which could be overridden according to the need of the application. In other words, you can
write
your own code to override the default code.
The Page class creates a hierarchical tree of all the controls on the page. All the components
on the
page, except the directives, are part of this control tree. You can see the control tree by
adding
trace= "true" to the page directive. We will cover page directives and tracing
under 'directives' and
'event handling'.
The page life cycle phases are:
Initialization
Instantiation of the controls on the page
Restoration and maintenance of the state
Execution of the event handler codes
Page rendering
Understanding the page cycle helps in writing codes for making some specific thing happen
at any
stage of the page life cycle. It also helps in writing custom controls and initializing them at
right time,
populate their properties with view-state data and run control behavior code.
Following are the different stages of an ASP page:
1. Page request - When ASP 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.
2. 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.
3. 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.
4. Page load - At this stage, control properties are set using the view state and control state
values.
5. Validation - Validate method of the validation control is called and on its successful
execution,
the IsValid property of the page is set to true.
6. Postback event handling - If the request is a postback (old request), the related event
handler
is invoked.
3. ASP Validation Server Controls
After you create a web form, you should make sure that mandatory fields of the form elements
such as login name and password are not left blank; data inserted is correct and is within the
specified range. Validation is the method of scrutinizing (observing) that the user has entered
the correct values in input fields.
A Validation server control is used to validate the data of an input control. If the data does not
pass validation, it will display an error message to the user.
Some of the validation server control are CompareValidator, RangeValidator,
CustomValidator, RequiredFieldValidator, etc.
The syntax for creating a Validation server control is:
<asp:regularexpressionvalidator id="some_ID" runat="server">
Eg:
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtUsername"
ErrorMessage="cannot be empty" ForeColor="Red">
</asp:RequiredFieldValidator>
Sample Program:
Write a server side program to design a webpage as below. The Username cannot be left
empty an d
Email should be in proper format. Password should be of 10 digits. Re-password should be
matching
with previous password. Make use of HTML, Web and Validation server controls as shown in
the
figure.
Default Page
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="default.aspx"
Inherits="Server_Controls_Example_in_ASP" %>
<!DOCTYPE html>
<html xmlns="w3/1999/xhtml">
<head runat="server">
<title>Account Creation</title>
</head>
<body>
<h1>Create Account</h1>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Username</td>
<td><asp:TextBox ID="txtUsername"
runat="server"></asp:TextBox></td>
<td ><asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="txtUsername"
ErrorMessage="cannot be empty"
ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Email</td>
<td><asp:TextBox ID="txtEmail"
runat="server"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ControlToValidate="txtEmail"
ErrorMessage="valid email required"
ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+).\
w+([-.]\w+)">
</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Password</td>
<td><asp:TextBox ID="txtPassword"
runat="server"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ControlToValidate="txtPassword"
ErrorMessage="10 digits required"
MaximumValue="9999999999" MinimumValue="1000000000"
Type="Integer"
ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><asp:TextBox ID="txtConfirm"
runat="server"></asp:TextBox></td>
<td><asp:CompareValidator ID="CompareValidator1"
runat="server"
ControlToCompare="txtPassword" ControlToValidate="txtConfirm"
ErrorMessage="must match
input password"
ForeColor="Red"></asp:CompareValidator></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><asp:Button ID="btnSave" runat="server"
OnClick="btnSave_Click"
Text="Save" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Output
If Username field is left blank then it is handled by the control name as
RequiredFieldValidation
control.
If Password is not matching,
5. Add New Table into your database.
6. Open the new table and you can fill the
data, which is like (studentname,
password) and afterwards, you click the
Update.
7. Here, the database and data are added.
8. Now, you can add SQL Data Source.
Drag and drop method. Here, click
Configure Data Source
9. Now, you can choose your database and
click NEXT button.
Select the ConnectionString and Click
NEXT button
Specify columns from a table or view and
afterwards, click Next button.
Test Query.
10.
####### Reference: c-sharpcorner/article/how-to-connect-sql-database-in-asp-net-using-c-sharp-
and-insert-and-view-the-data-usi/
5. Data Access
ADO Architecture
The .NET Framework includes its own data access technology: ADO. ADO consists of
managed classes that allow .NET applications to connect to data sources (usually relational
databases), execute commands, and manage disconnected data. The small miracle of ADO is
that it allows us to write more or less the same data access code in web applications that we
write for
client-server desktop applications, or even single-user applications that connect to a local
database.
The figure below represents the ADO architecture:
Figure: The ADO architecture
ADO consists of a set of Objects that expose data access services to the .NET environment.
It is
a data access technology from Microsoft .Net Framework, which provides communication
between
relational and non relational systems through a common set of components.
The two key components of ADO are DataSet and Data Providers.
1. DataSet class provides mechanisms for managing data when it is disconnected from the
data
source.
Sql Server connection string is (for SQL server authentication) :
string connectionString = "Data Source= ServerName ; Initial Catalog= DatabaseName ;
User ID= UserName ; Password= Password ” ;
Eg:
string cs = "Data Source= myDatabase ; Initial Catalog= localhost ;
User ID=sa ; Password= pokhara ” ;
Testing Connection:
Once we’ve chosen our connection string, managing the connection is easy—we simply use
the
Open() and Close() methods.
We can use the following code in the Page event handler to test a connection and write its
status to a label. To use the connection code, we must import the System.Data
namespace.
// Default.aspx
{
// Create the Connection object.
string cs = "Data Source=localhost; database=myDatabase; integrated
security=SSPI";
// we can write database instead of initial catalog
SqlConnection con = new SqlConnection(cs);
try // Try to open the connection.
{
con();
// gives server version
Label1 = "<b>Server Version:</b> " + con;
// gives the status
Label1 += "<br /><b>Connection Is:</b> " + con.State();
}
catch (Exception err) // Handle an error by displaying the information.
{
Label1 = "Error reading the database. " + err;
}
finally
{
// Either way, make sure the connection is properly closed.
// Even if the connection wasn't opened successfully,
// calling Close() won't cause an error.
con();
Label1 += "<br /><b>Now Connection Is:</b> " +con.State();
}
}
If the connection is successful, you should get the message as:
Refer: guru99/insert-update-delete-asp-net.html
2. Command Class
The Command class allows us to execute any type of SQL statement.
Although we can use a Command class to perform data definition tasks (such as creating
and
altering databases, tables, and indexes), we’re much more likely to perform data
manipulation
tasks (such as retrieving and updating the records in a table).
Command Basics
Before we can use a command, we need to:
choose the command type,
set the command text, and
bind the command to a connection.
We can perform this work by setting the corresponding properties (CommandType,
CommandText,
and Connection), or we can pass the information we need as constructor arguments.
The command text can be a SQL statement, a stored procedure, or the name of a table. It all
depends
on the type of command we’re using. Three types of commands exist.
####### Table: Values for the Command Type Enumeration
Example:
Here is how we would create a Command object that represents a query.
SqlCommand cmd = new SqlCommand();
cmd = con;
cmd = System.Data.CommandType;
cmd = "SELECT * FROM info";
CommandType is the default. So we may not specify it, and write the above code simply as:
SqlCommand cmd = new SqlCommand("Select * from info", con);
Alternatively, to use stored procedure:
SqlCommand cmd = new SqlCommand("Select * from info", con);
cmd = System.Data.CommandType;
Fundamental ADO classes
ADO has two types of objects: connection-based and content-based.
1. Connection-based objects:
These are the data provider objects such as Connection, Command, DataReader, and
DataAdapter.
They allow us to connect to a database, execute SQL statements, move through a read-only
result set, and fill a DataSet.
2. Content-based objects:
These objects are really just “packages” for data.
They include the DataSet, DataColumn, DataRow, DataRelation, and several others.
They are completely independent of the type of data source and are found in the System
namespace.
Table: The ADO Namespace
5. Database Access without ADO
In ASP, there are a few ways to get information out of a database without directly using the
ADO classes. Depending on our needs, we may be able to use one or more of these
approaches
to supplement your database code (or to avoid writing it altogether). The options for
database access
without ADO include the following:
1. The SqlDataSource control:
The SqlDataSource control allows us to define queries declaratively. We can connect the
SqlDataSource to rich controls such as the GridView, and give our pages the ability to edit
and update data without requiring any ADO code.
2. LINQ to Entities:
With LINQ to Entities, we define a query using C# code (or the LinqDataSource control) and
the appropriate database logic is generated automatically. LINQ to Entities supports updates,
generates secure and well-written SQL statements, and provides some customizability. LINQ
to Entities is the successor of LINQ to SQL. Unlike the SqlDataSource control, LINQ to SQL
only works with SQL Server and is completely independent of ADO
3. Profiles:
The profiles feature allows you to store user-specific blocks of data in a database without
writing ADO code.
Sample Program 1:
A database dbBook has a table called tbBookInfo having attributes bookId, bookname,
authorname,
publisher and price. Using ADO and ASP, WAP to read all the records from the table and
display them.
Default.aspx
using System;
using System.Collections;
using System;
using System;
using System.Web;
using System.Web.UI;
using System.Data;
namespace Data_Connection_Teaching
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
string cs = "Data Source=localhost; database=dbBook; integrated
security=SSPI";
SqlConnection con = new SqlConnection(cs);
try
{
con();
SqlCommand cmd = new SqlCommand("Select * from tbBookInfo", con);
GridView1 = cmd();
GridView1();
}
catch
{
Console("Error");
}
finally
{
con();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Refer: guru99/insert-update-delete-asp-net.html
Download
AI Tools
Multiple Choice
Flashcards
Quiz Video
Audio Lesson
00
Save
Document continues below
Discover more from:
Programming Technology
CMP 211
Pokhara University
35 Documents
Go to course
14
java assignment
100%(3)
18
Programming - Old Question Collection of P-T BE Computer - IV
100%(2)
10
Aptassign - Summary Programming Technology
Programming Technology100%(1)
34
Chapter 3 of pt
Programming TechnologyNone
11
Chapter 4 of pt
Programming TechnologyNone
16
Chapter 2 of pt
Programming TechnologyNone
5. WEB AND DATABASE
PROGRAMMING WITH .NET
80
Programming Technology © Er. Shiva
Ram Dam, 2019
Fundamental ADO.net
classes
ADO.NET has two types of
objects: connection-based and
content-based.
1. Connection-based objects:
• These are the data
provider objects such as
Connection, Command,
DataReader, and
DataAdapter
.
• They allow us to
connect to a database,
execute SQL statements,
move through a read-only
result set, and fill a DataSet
.
2. Content-based objects:
• These objects are really
just “packages” for data.
• They include the
DataSet, DataColumn,
DataRow, DataRelation, and
several others
.
• They are completely
independent of the type of
data source and are found in
the System.Data
namespace.
Table: The ADO.NET Namespace
5.9. Database Access
without ADO.NET
In ASP.NET, there are a few
ways to get information out
of a database without
directly using the
ADO.NET classes. Depending
on our needs, we may be able
to use one or more of these
approaches
to supplement your database
code (or to avoid writing it
altogether). The options for
database access
without ADO.NET include the
following:
1. The
SqlDataSource
control:
The
SqlDataSource
control allows us to define
queries declaratively. We
can connect the
SqlDataSource
to rich controls such as the
GridView, and give our
pages the ability to edit
and update data without
requiring any ADO.NET code.
5. WEB AND DATABASE
PROGRAMMING WITH .NET
Programming Technology © Er. Shiva
Ram Dam, 2019
81
2. LINQ to Entities:
With LINQ to Entities, we
define a query using C# code
(or the
LinqDataSource
control) and
the appropriate database logic
is generated automatically.
LINQ to Entities supports
updates,
generates secure and well-
written SQL statements, and
provides some customizability.
LINQ
to Entities is the successor of
LINQ to SQL. Unlike the
SqlDataSource control, LINQ to
SQL
only works with SQL Server
and is completely independent
of ADO.NET
3. Profiles:
The profiles feature allows
you to store user-specific
blocks of data in a
database without
writing ADO.NET code.
Sample Program 1:
A database dbBook has a table
called tbBookInfo having
attributes bookId, bookname,
authorname,
publisher and price. Using
ADO.net and ASP.net, WAP
to read all the records from
the table and
display them.
//Default.aspx.cs
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace
Data_Connection_Teaching
{
public partial class _Default :
Page
{
protected void
Page_Load(object sender,
EventArgs e)
{
string cs = "Data
Source=localhost;
database=dbBook; integrated
security=SSPI";
SqlConnection con =
new SqlConnection(cs);
try
{
con.Open();
SqlCommand cmd =
new SqlCommand("Select *
from tbBookInfo", con);
GridView1.DataSource
= cmd.ExecuteReader();
GridView1.DataBind();
}
catch
{
Console.WriteLine("Error");
}
finally
{
con.Close();
}
}
protected void
GridView1_SelectedIndexChang
ed(object sender, EventArgs e)
{
}
}
}
Refer:
https://www.guru99.com/insert-
update-delete-asp-net.html
More from:
Programming Technology
(CMP 211)
Programming Technology
CMP 211
Pokhara University
35 Documents
Go to course
14
java assignment
Programming Technology100%(3)
18
Programming - Old Question Collection of P-T BE Computer - IV
Programming Technology100%(2)
10
Aptassign - Summary Programming Technology
Programming Technology100%(1)
90
Python Coding for Beginners 20Ed2024
Programming TechnologyNone
3
Job Description - Software Developer
Programming TechnologyNone
16
UNIT IX - 6. Event Handling
Programming TechnologyNone
More from:Sandesh Lamsal
Sandesh Lamsal
impact7
Gandaki Boarding School
Discover more
16
Chapter 2 of pt
Programming TechnologyNone
11
Chapter 4 of pt
Programming TechnologyNone
34
Chapter 3 of pt
Programming TechnologyNone
Recommended for you
14
java assignment
Programming Technology100%(3)
18
Programming - Old Question Collection of P-T BE Computer - IV
Programming Technology100%(2)
10
Aptassign - Summary Programming Technology
Programming Technology100%(1)
Company
About us
Studocu Premium
Ask AI
AI Notes
Notes to Quiz Videos
Notes to Audio
Studocu World University Ranking 2023
E-Learning Statistics
Doing Good
Academic Integrity
Jobs
Blog
Dutch Website
Contact & Help
F.A.Q.
Contact
Newsroom
Legal
Terms
Privacy policy
Cookie Settings
Cookie Statement
View our reviews on Trustpilot
English
Rest of the World
Studocu is not affiliated to or endorsed by any school, college or university.
Copyright © 2025 StudeerSnel B.V., Keizersgracht 424-sous, 1016 GC Amsterdam, KVK: 56829787, BTW:
NL852321363B01
17