SlideShare a Scribd company logo
Introduction to ASP.NET
Week 11, day1
ASP
Active Server Pages
‚ASP.NET is a server side scripting language‛
.NET overview
•.NET is a framework for developing web-based and
windows-based applications within the Microsoft
environment.
• Components of .NET
 MICROSOFT Intermediate language - all code is
complied into a more abstract, trimmed version before
execution. All .NET languages are compiled to MSIL –
the common language of .NET
The CLR- common language runtime; responsible for
executing MSIL code; interfaces to Windows and IIS
A rich set of libraries (Framework Class Libraries)
available to all .NET languages
Components of .NET (Continuation)
The .NET languages such as C#, VB.NET etc that
conform to CLR
ASP.NET is how the Framework is exposed to the
web, using IIS (internet information system) to manage
simple pages of code so that they can be complied into
full .NET programs. These generate HTML for the
browser (when the page is requested by a client
browser).
Generate HTML
Get index.aspx
1
3
4
pass index.aspx to .net
framework
5
WebServer
Index.aspx in
interpreted HTMl form
Browser
2
Get index.aspx from
hard disk
How IIS takes requests and processes it
.NET
Scripting Languages
• A ‚script‛ is a collection of program or sequence of instructions that is
interpreted or carried out by another program rather than by the computer
processor. Two types of scripting languages are
– Client-side Scripting Language
– Server-side Scripting Language
• In server-side scripting, (such as PHP, ASP) the script is processed by the
server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows.
• Client-side scripting such as JavaScript runs on the web browser.
Generate HTML
Get index.aspx
1
3
4
pass index.aspx to .net
framework
5
WebServer
Index.aspx in
interpreted HTMl form
Browser
2
Get index.aspx from
hard disk
How IIS takes requests and processes it
.NET
ASP.NET is a server side
scripting language because the
code runs on the server and
returns the result in html form
to the client browser
Generate HTML
Get index.aspx
1
3
4
pass index.aspx to .net
framework
5
WebServer
Index.aspx in
interpreted HTMl form
Browser
2
Get index.aspx from
hard disk
How IIS takes requests and processes it
.NET
Client side scripting is something
where code runs on client
side(browser). For eg checking
whether a HTML text field contains
data or not can be done by running
a script from browser itself
Microsoft Visual Studio
•Microsoft Visual Studio is an IDE (Integrated Development
Environment) on which .net applications can be created
easily.
•It is a powerful tool that can expose the features of the
.net framework to make the developers work easier
•Applications can be run from within the IDE and has
inbuilt compiler and debugger (no need to install third
party servers like WAMP, XAMPP etc. to run the application
as in case of PHP)
•It exposes a rich design based interface to manage any
aspect of a .net project from design to deployment
Creating an asp.net page
Create a new asp.net website project
Go to start > all programs > microsoft visual studio 2008 (or whatever version
you have installed)
Create a new asp.net website project
Click on file > new web site
Create a new asp.net website project
(for C# select the language as Visual C#)
Create a new asp.net website project
Create a new asp.net website project
Create a new asp.net website project
Create a new asp.net website project
Create a new asp.net website project
• Double click on the button control you just created
Create a new asp.net website project
• You can also add handlers for other events of the button
Adding connection string to the web.config file
Adding a new item to the project
Adding a new item to the project
Running the project
Getting started with ASP.NET programming
.Net Controls, Events and Event handlers
• .net Controls –
 There are no. of controls those are available in the toolbox inside visual
studio. Eg. Button, textbox, dropdownlist etc.
 Each control represents a class extended from
the System.Web.UI.WebControls class
 Each control has events, properties and methods associated with it
 Each control in an aspx page is identified by a unique id, no two controls
on the same page can share an id
• Events
 Events happen when the user does some sort of action on a control eg.
Click for a button, changing the text for a textbox etc.
• Event Handlers
 Event handlers are code blocks that will be executed when events are
raised
.Net Controls, Events and Event handlers (continuation)
 In plain words an event handler for the click of a button that has an id
“btn_a” will tell the server like
“Do this on the click of btn_a”
 There are no. of event handlers associated with each type of .net control
 Custom event handlers can also be registered for certain controls.
Commenting
// comment single line
/* comment
multiple lines */
C#
//comment single line
/* Comment
multiple Lines*/
VB.NET
‘comment single line
/* Comment
multiple Lines*/
C ASP.NET
Data Types
Data types
• ASP.NET supports many different data types such as
o Integer
o String
o Double
o Boolean
o Datetime
o Arrays
Type Casting
 Response.write ((0.1 + 0.7) * 10); //Outputs 8
 Response.write ([cint] ((0.1 + 0.7) * 10));//Outputs 7
• This happens because the result of this simple arithmetic
expression is stored internally as 7.999999 instead of 8; when the
value is converted to integer, ASP.NET simply truncates away the
fractional part, resulting in a rather significant error (12.5%, to be
exact).
Variables
Declaring a variable
//Declaring a variable
Int a=10;
Char c=‘a’;
Float f=1.12;
C#
String a; //variable without initialisation
String a = ‚Hello‛; //variable with
initialisation
VB.NET
Dim a as string //variable without
initialisation
dim a as string = ‚Hello‛ //variable with
initialisation
C ASP.NET
Variables
• Variables are temporary storage containers.
• In ASP.NET, a variable can contain any type of data, such as, for example,
strings, integers, floating numbers, objects and arrays provided the variable
must be declared in that datatype.
• As in case of PHP which is loosely typed, ASP.NET will not implicitly
change the type of a variable as needed. ASP.NET languages are strongly
typed, like C and Java, where variables can only contain one type of data
throughout their existence.
Constants
Declaring a constant
//Declaring a constant using ‘const’
const int a=10;
int const a=10;
//Declaring a constant using ‘#define’
#define TRUE 1
#define FALSE 0
#define NAME_SIZE 20
C#
Const String a = ‚Hello‛;
VB.NET
const a as string = ‚Hello‛
C ASP.NET
Constants
• Conversely to variables, constants are meant for defining immutable
values.
• Compile-time and Run-time Constants
A compile-time constant is computed at the time the code is compiled,
while a run-time constant can only be computed while the application is
running. A compile-time constant will have the same value each time an
application runs, while a run-time constant may change each time.
Control structures
Control Structures
Conditional Control Structures
• If
• If else
• Switch
Loops
For
While
Do while
Other
• Break
• Continue
‚Exactly the same as on left side‛
+
• return
• go to
C ASP.NET
functions
Functions
Int findSum(int a,int b)
{
Int c;
c=a+b;
Return c
}
findSum(10,15);
function findSum(byVal a as
integer,byVal b as integer)
Dim c as integer
c=a+b
Return c
End function
Dim d as integer = findSum(10,15)
Response.write(d) ‘output : 25
C ASP.NET (vb.net example)
Functions
public int findSum(int a, int b) {
int c;
c = (a + b);
return c;
}
private int d = findSum(10, 15);
Response.write(d); //output : 25
ASP.NET (C# example)
Function arguments
• You can define any number of arguments to an ASP.NET function.
• Arguments can be passed by reference(byRef) or by value (byValue)
o byRef - When an argument is passed by reference, the called
procedure can change the value of the variable. The change persists
after the procedure is called
o byValue - When an argument is passed by value, any changes that the
called procedure makes to the value of the variable do not persist
after the procedure is called.
Function return type
• The function return type can also be defined in the function
declaration
– VB.net
Function findSum(byval a as integer, byval b as integer) as integer
Dim c as integer
c=a+b
Return c
End function
– C#
public int findSum(int a, int b) {
int c;
c = (a + b);
return c;
}
Function return type
• A function without a return value is called as a sub routine
and is defined as follows in ASP.NET
– Vb.net
private sub findSum(byval a as integer, byval b as integer)
Dim c as integer
c=a+b
End sub
– C#
Protected void findSum(int a, int b)
{
int c;
c=a+b;
}
Strings
Char a*+=‚Baabtra‛;
Printf(‚Hello %s‛,a);
Dim a as string =‚Baabtra‛
Response.write( ‚Hello ‛ + a) //Output:
Hello baabtra
Response.write( ‚Hello + a‛) //Output:
Hello + a
‚Strings will be continued in coming
chapters‛
C ASP.NET
Arrays
Indexed Array
int a[]={1,2,3,4,5,6,7,8,9,10};
for(i=0;i<10;i++)
Printf(‚%d‛,a[i]);
‚Array will be continued in coming
chapters‛
Declaring an array of strings
Vb.net
Dim arrStr as string() //without
initialisation
Dim arrStr as string() = (‚a‛, ‚b‛)
//with initialisation
C#
string[] arrStr ;//without
initialisation
string[] arrStr = new string[] {
"one", "two", "three" } //with
initialisation
C ASP.NET
Operators
Operators
C
Arithmetic Operators
+, ++, -, --, *, /, %
Comparison Operators
==, !=, ===, !==, >, >=, < , <=
Logical Operators
&&, ||, !
Assignment Operators
=, +=, -=, *=, /=, %=
ASP.NET
Arithmetic Operators
Ope
rato
r
description Example Re
sul
t
+ Addition myNum = 3 + 4 7
- Subtraction myNum = 4 - 3 1
* Multiplication myNum = 3 * 4 12
/ Division myNum = 12 /4 3
^ Exponential myNum = 2 ^ 4 16
Mod Modulus myNum = 23
Mod 10
3
- Negation myNum = -10 -10
 Integer
Division
myNum = 9  3 3
Comparison operators
Operator description Example Result
= Equal to 3 = 4 false
< Less than 4 < 3 false
> Greater than 4 > 3 true
<= Less than or equal to 4 <= 4 true
>= Greater than or equal to 4 >= 5 false
<> / != Not equal to 4 <> 3 / 4 != 3 true
Logical operators
Operator description Example Result
And / && Both Must be TRUE True And False false
Or / || One Must be TRUE True Or False true
Not / ! Flips Truth Value Not true false
String operators
Operator description Example Result
& / +
String Concatenation string4 = “Hello" & " world"
string4 = “Hello
world"
• Bitwise operators allow you to manipulate bits of data. All these operators are
designed to work only on integer numbers—therefore, the interpreter will attempt
to convert their operands to integers before executing them.
Bitwise Operators
AND Bitwise AND. The result of the operation will be a value whose bits are set if they are set
in both operands, and unset otherwise.
OR Bitwise OR. The result of the operation will be a value whose bits are set if they are set in
either operand (or both), and unset otherwise.
XOR Bitwise XOR (exclusive OR). The result of the operation will be a value whose bits are set
if they are set in either operand, and unset otherwise.
NOT Bitwise NOT. inverts each bit in a sequence of bits. A 0 becomes a 1, and a 1 becomes
a 0.
<< Bitwise left shift. This operation shifts the left-hand operand’s bits to the left by a number
of positions equal to the right operand, inserting unset bits in the shifted positions
>> Bitwise right shift. This operation shifts the left-hand operand’s bits to the right by a
number of positions equal to the right operand, inserting unset bits in the shifted
positions.
End of day 1
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

ASP.NET Basics

  • 2. ASP Active Server Pages ‚ASP.NET is a server side scripting language‛
  • 3. .NET overview •.NET is a framework for developing web-based and windows-based applications within the Microsoft environment. • Components of .NET  MICROSOFT Intermediate language - all code is complied into a more abstract, trimmed version before execution. All .NET languages are compiled to MSIL – the common language of .NET The CLR- common language runtime; responsible for executing MSIL code; interfaces to Windows and IIS A rich set of libraries (Framework Class Libraries) available to all .NET languages
  • 4. Components of .NET (Continuation) The .NET languages such as C#, VB.NET etc that conform to CLR ASP.NET is how the Framework is exposed to the web, using IIS (internet information system) to manage simple pages of code so that they can be complied into full .NET programs. These generate HTML for the browser (when the page is requested by a client browser).
  • 5. Generate HTML Get index.aspx 1 3 4 pass index.aspx to .net framework 5 WebServer Index.aspx in interpreted HTMl form Browser 2 Get index.aspx from hard disk How IIS takes requests and processes it .NET
  • 6. Scripting Languages • A ‚script‛ is a collection of program or sequence of instructions that is interpreted or carried out by another program rather than by the computer processor. Two types of scripting languages are – Client-side Scripting Language – Server-side Scripting Language • In server-side scripting, (such as PHP, ASP) the script is processed by the server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows. • Client-side scripting such as JavaScript runs on the web browser.
  • 7. Generate HTML Get index.aspx 1 3 4 pass index.aspx to .net framework 5 WebServer Index.aspx in interpreted HTMl form Browser 2 Get index.aspx from hard disk How IIS takes requests and processes it .NET ASP.NET is a server side scripting language because the code runs on the server and returns the result in html form to the client browser
  • 8. Generate HTML Get index.aspx 1 3 4 pass index.aspx to .net framework 5 WebServer Index.aspx in interpreted HTMl form Browser 2 Get index.aspx from hard disk How IIS takes requests and processes it .NET Client side scripting is something where code runs on client side(browser). For eg checking whether a HTML text field contains data or not can be done by running a script from browser itself
  • 9. Microsoft Visual Studio •Microsoft Visual Studio is an IDE (Integrated Development Environment) on which .net applications can be created easily. •It is a powerful tool that can expose the features of the .net framework to make the developers work easier •Applications can be run from within the IDE and has inbuilt compiler and debugger (no need to install third party servers like WAMP, XAMPP etc. to run the application as in case of PHP) •It exposes a rich design based interface to manage any aspect of a .net project from design to deployment
  • 11. Create a new asp.net website project Go to start > all programs > microsoft visual studio 2008 (or whatever version you have installed)
  • 12. Create a new asp.net website project Click on file > new web site
  • 13. Create a new asp.net website project (for C# select the language as Visual C#)
  • 14. Create a new asp.net website project
  • 15. Create a new asp.net website project
  • 16. Create a new asp.net website project
  • 17. Create a new asp.net website project
  • 18. Create a new asp.net website project • Double click on the button control you just created
  • 19. Create a new asp.net website project • You can also add handlers for other events of the button
  • 20. Adding connection string to the web.config file
  • 21. Adding a new item to the project
  • 22. Adding a new item to the project
  • 24. Getting started with ASP.NET programming
  • 25. .Net Controls, Events and Event handlers • .net Controls –  There are no. of controls those are available in the toolbox inside visual studio. Eg. Button, textbox, dropdownlist etc.  Each control represents a class extended from the System.Web.UI.WebControls class  Each control has events, properties and methods associated with it  Each control in an aspx page is identified by a unique id, no two controls on the same page can share an id • Events  Events happen when the user does some sort of action on a control eg. Click for a button, changing the text for a textbox etc. • Event Handlers  Event handlers are code blocks that will be executed when events are raised
  • 26. .Net Controls, Events and Event handlers (continuation)  In plain words an event handler for the click of a button that has an id “btn_a” will tell the server like “Do this on the click of btn_a”  There are no. of event handlers associated with each type of .net control  Custom event handlers can also be registered for certain controls.
  • 27. Commenting // comment single line /* comment multiple lines */ C# //comment single line /* Comment multiple Lines*/ VB.NET ‘comment single line /* Comment multiple Lines*/ C ASP.NET
  • 29. Data types • ASP.NET supports many different data types such as o Integer o String o Double o Boolean o Datetime o Arrays
  • 30. Type Casting  Response.write ((0.1 + 0.7) * 10); //Outputs 8  Response.write ([cint] ((0.1 + 0.7) * 10));//Outputs 7 • This happens because the result of this simple arithmetic expression is stored internally as 7.999999 instead of 8; when the value is converted to integer, ASP.NET simply truncates away the fractional part, resulting in a rather significant error (12.5%, to be exact).
  • 32. Declaring a variable //Declaring a variable Int a=10; Char c=‘a’; Float f=1.12; C# String a; //variable without initialisation String a = ‚Hello‛; //variable with initialisation VB.NET Dim a as string //variable without initialisation dim a as string = ‚Hello‛ //variable with initialisation C ASP.NET
  • 33. Variables • Variables are temporary storage containers. • In ASP.NET, a variable can contain any type of data, such as, for example, strings, integers, floating numbers, objects and arrays provided the variable must be declared in that datatype. • As in case of PHP which is loosely typed, ASP.NET will not implicitly change the type of a variable as needed. ASP.NET languages are strongly typed, like C and Java, where variables can only contain one type of data throughout their existence.
  • 35. Declaring a constant //Declaring a constant using ‘const’ const int a=10; int const a=10; //Declaring a constant using ‘#define’ #define TRUE 1 #define FALSE 0 #define NAME_SIZE 20 C# Const String a = ‚Hello‛; VB.NET const a as string = ‚Hello‛ C ASP.NET
  • 36. Constants • Conversely to variables, constants are meant for defining immutable values. • Compile-time and Run-time Constants A compile-time constant is computed at the time the code is compiled, while a run-time constant can only be computed while the application is running. A compile-time constant will have the same value each time an application runs, while a run-time constant may change each time.
  • 38. Control Structures Conditional Control Structures • If • If else • Switch Loops For While Do while Other • Break • Continue ‚Exactly the same as on left side‛ + • return • go to C ASP.NET
  • 40. Functions Int findSum(int a,int b) { Int c; c=a+b; Return c } findSum(10,15); function findSum(byVal a as integer,byVal b as integer) Dim c as integer c=a+b Return c End function Dim d as integer = findSum(10,15) Response.write(d) ‘output : 25 C ASP.NET (vb.net example)
  • 41. Functions public int findSum(int a, int b) { int c; c = (a + b); return c; } private int d = findSum(10, 15); Response.write(d); //output : 25 ASP.NET (C# example)
  • 42. Function arguments • You can define any number of arguments to an ASP.NET function. • Arguments can be passed by reference(byRef) or by value (byValue) o byRef - When an argument is passed by reference, the called procedure can change the value of the variable. The change persists after the procedure is called o byValue - When an argument is passed by value, any changes that the called procedure makes to the value of the variable do not persist after the procedure is called.
  • 43. Function return type • The function return type can also be defined in the function declaration – VB.net Function findSum(byval a as integer, byval b as integer) as integer Dim c as integer c=a+b Return c End function – C# public int findSum(int a, int b) { int c; c = (a + b); return c; }
  • 44. Function return type • A function without a return value is called as a sub routine and is defined as follows in ASP.NET – Vb.net private sub findSum(byval a as integer, byval b as integer) Dim c as integer c=a+b End sub – C# Protected void findSum(int a, int b) { int c; c=a+b; }
  • 45. Strings Char a*+=‚Baabtra‛; Printf(‚Hello %s‛,a); Dim a as string =‚Baabtra‛ Response.write( ‚Hello ‛ + a) //Output: Hello baabtra Response.write( ‚Hello + a‛) //Output: Hello + a ‚Strings will be continued in coming chapters‛ C ASP.NET
  • 46. Arrays Indexed Array int a[]={1,2,3,4,5,6,7,8,9,10}; for(i=0;i<10;i++) Printf(‚%d‛,a[i]); ‚Array will be continued in coming chapters‛ Declaring an array of strings Vb.net Dim arrStr as string() //without initialisation Dim arrStr as string() = (‚a‛, ‚b‛) //with initialisation C# string[] arrStr ;//without initialisation string[] arrStr = new string[] { "one", "two", "three" } //with initialisation C ASP.NET
  • 48. Operators C Arithmetic Operators +, ++, -, --, *, /, % Comparison Operators ==, !=, ===, !==, >, >=, < , <= Logical Operators &&, ||, ! Assignment Operators =, +=, -=, *=, /=, %= ASP.NET Arithmetic Operators Ope rato r description Example Re sul t + Addition myNum = 3 + 4 7 - Subtraction myNum = 4 - 3 1 * Multiplication myNum = 3 * 4 12 / Division myNum = 12 /4 3 ^ Exponential myNum = 2 ^ 4 16 Mod Modulus myNum = 23 Mod 10 3 - Negation myNum = -10 -10 Integer Division myNum = 9 3 3
  • 49. Comparison operators Operator description Example Result = Equal to 3 = 4 false < Less than 4 < 3 false > Greater than 4 > 3 true <= Less than or equal to 4 <= 4 true >= Greater than or equal to 4 >= 5 false <> / != Not equal to 4 <> 3 / 4 != 3 true
  • 50. Logical operators Operator description Example Result And / && Both Must be TRUE True And False false Or / || One Must be TRUE True Or False true Not / ! Flips Truth Value Not true false String operators Operator description Example Result & / + String Concatenation string4 = “Hello" & " world" string4 = “Hello world"
  • 51. • Bitwise operators allow you to manipulate bits of data. All these operators are designed to work only on integer numbers—therefore, the interpreter will attempt to convert their operands to integers before executing them. Bitwise Operators AND Bitwise AND. The result of the operation will be a value whose bits are set if they are set in both operands, and unset otherwise. OR Bitwise OR. The result of the operation will be a value whose bits are set if they are set in either operand (or both), and unset otherwise. XOR Bitwise XOR (exclusive OR). The result of the operation will be a value whose bits are set if they are set in either operand, and unset otherwise. NOT Bitwise NOT. inverts each bit in a sequence of bits. A 0 becomes a 1, and a 1 becomes a 0. << Bitwise left shift. This operation shifts the left-hand operand’s bits to the left by a number of positions equal to the right operand, inserting unset bits in the shifted positions >> Bitwise right shift. This operation shifts the left-hand operand’s bits to the right by a number of positions equal to the right operand, inserting unset bits in the shifted positions.
  • 53. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 54. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com