Web Technology
Web Technology
Web Technology
UNIT – 1:
Internet Basic – Introduction to HTML – List Creating Table – Linking document
– Frames - Graphics to HTML Doc – Style sheet – style sheet basic – Add style to
document – Creating style sheet rules – Style sheet properties – Font – Text – List –
Color and Background color – Box – Display properties.
UNIT – 2:
Introduction to JavaScript – Advantage of JavaScript – JavaScript syntax – Data
type – Variable – Array – Operator and Expression – Looping Constructor – Function
– Dialog box.
UNIT – 3:
JavaScript document object model – Introduction – object in HTML – Event
Handling – Window object – Document object – Browser Object – Form Object –
Navigator object – Screen object – Build in object – User defined object – Cookies.
UNIT – 4:
ASP.NET Languages structure – Page event, Properties & Compiler Directives.
HTML server controls – Anchor, Tables, Forms, Forms, Files. Basic web server
Controls – Label, Textbox, Button, Image, Links, Check & Radio button, Hyperlink.
Data list Web server controls – Check box list, Radio button list, Drop down list, List
box, and Data grid, Repeater.
UNIT – 5:
Request and Response Objects, Cookies, Working with Data – OLEDB
connection class, Command class transaction class, data adaptor class, data set class.
Advanced Issues – Email, Application Security – Authentication, IP Address, Secure
by SSL & Client Certificates.
Internet Basic:
This information is almost always retrieved using the Hypertext Transfer Protocol
(HTTP). In fact HTTP has been in use by the World Wide Web since 1989, and its use
has increased steadily over the years. Today there are millions of Web sites on the
World Wide Web, all of them using HTTP
Current Servers
Google- http://www.google.com
Info seek- http://guide.infoseek.com
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 2
Alta Vista – http://www.altavista.digital.com
Lycos – http://www.lycos.com
Yahoo! – http://www.yahoo.com
Domain
n o m in u m m e ta in fo b e r k e le y nwu n a to a rm y uu
w est ea st w w w
d a k o ta to rn a d o
The top level domains
net ... for network operations and Internet Service Providers (ISP)
Consists of 4 parts:
Directory
Filename
Example: http://www.google.com
TCP/IP
TCP is a lossless protocol, requiring a handshake to insure that data is not lost during
transmission.
Internet Protocol (IP) uses addresses which are a series of four "octet" (byte)
numbers in a dotted decimal notation. For example: 199.246.24.130
Internet (internetworking) Layer: The Internet Layer has the task of exchanging
datagram across network boundaries. It is therefore also referred to as the layer that
establishes internetworking; indeed, it defines and establishes the Internet
Link Layer: This layer defines the networking methods with the scope of the local
network link on which hosts communicate without intervening routers. This layer
describes the protocols used to describe the local network topology and the interfaces
needed to affect transmission of Internet Layer datagram’s to next-neighbor hosts.
Internet Use:
HTML
HTML Tags
HTML markup tags are usually called HTML tags
HTML tags are keywords surrounded by angle brackets like <html>
HTML tags normally come in pairs like <b> and </b>
The first tag in a pair is the start tag, the second tag is the end tag
Start and end tags are also called opening tags and closing tags
HTML Documents = Web Pages
HTML documents describe web pages
HTML documents contain HTML tags and plain text
The purpose of a web browser (like Internet Explorer or Firebox) is to read HTML
documents and display them as web pages. The browser does not display the HTML
tags, but uses the tags to interpret the content of the page
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph</p> </body> </html>
Example Explained
The text between <html> and </html> describes the web page
The text between <body> and </body> is the visible page content
The element content is everything between the start and the end tag
Tag Description
Basic
Formatting
Forms
Frames
<noframes> Defines an alternate content for users that do not support frames
Images
Links
<link /> Defines the relationship between a document and an external resource
Lists
Tables
<col /> Defines attribute values for one or more columns in a table
Styles
Meta Info
<base /> Defines a default address or a default target for all links on a page
<basefont /> Deprecated. Defines a default font, color, or size for the text in a page
<noscript> Defines an alternate content for users that do not support client-side scripts
Text property
This page deals with html tags for formatting a webpage with text and will show
how to create a headline, how to make paragraphs, how to pick fonts and change
their color and size .Use the H tag to create a headline, the h tag comes in six
flavors
<h6>Heading 6</h6>
Text align
Example
<H5 align=left>Hello World</H5>
Fonts are one of the most important visual elements of your page and if you're
like most web designers you'll want to set a few fonts in every page.
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 10
Probably the most versatile text formatting tag is the <FONT></FONT> tag the
font tag not only allows the color and size of text to be selected but also allows
specific fonts to be selected
The font tag gives enough flexibility to allow html authors to specify a 'back
up' font
Font styles
use the <B></B> tags to make text <B>bold</B>
Horizontal Rule
Here's a horizontal rule... <hr /> ...that was a horizontal rule :)
Example Program
<html><body>
</center>
</body></html>
Listing Property
Unordered lists
NUMBERED LISTS
Plain numbers
Capital Letters
Small Letters
<ol><li>text</li> 1. text
<li>text</li></ol>
2. text
To create a hyperlink, you use the tag in conjunction with the href attribute
(href stands for Hypertext Reference). The value of the href attribute is the URL, or,
location of where the link is pointing to.
Hyper Link syntax:
The element content doesn't have to be text. You can link from an image or any other
HTML element.
Example:
Image Link
To display an image on a page, you need to use the src attribute. Src stands for
"source". The value of the src attribute is the URL of the image you want to display
on your page..
To embed an image into a web page, the image first needs to exist in either .jpg, .gif,
or .png format.
Example:
Src: This is the path to the image. It can be either an absolute path, or a relative
path
Width: This specifies the width to display the image. If the actual image is wider, it
will shrink to the dimensions you specify here. Likewise, if the actual image is smaller
it will expand to your dimensions. I don't recommend specifying a different size for
the image, as it will lose quality. It's better to make sure the image is the correct size
to start with.
Height: This specifies the height to display the image. This attribute works similar to
the width
Alt: Alternate text. This specifies text to be used in case the browser/user agent
can't render the image.
E-mail Link
<a href="mailto:[email protected]?subject=Hello%20Sir">
Send Mail</a>
Example Program
<html><body><p>
<a href="mailto:[email protected]?subject=Hello%20sir">
</body></html>
HTML Colors
Colors are displayed combining RED, GREEN, and BLUE light.
HTML colors are defined using a hexadecimal (hex) notation for the combination of
Red, Green, and Blue color values (RGB).
The lowest value that can be given to one of the light sources is 0 (hex 00). The
highest value is 255 (hex FF).
Hex values are written as 3 double digit numbers, starting with a # sign.
Font color
Set the color of your font with color
Example:
Background Color :
Border color:
HTML Tables
A table is a two dimensional matrix ,consiter od rows and coloms .Table are
intended for displaying data in coloumns on web page.Tables are defined with the
<table> tag. A table is divided into rows (with the <tr> tag), and each row is divided
into data cells (with the <td> tag). The letters td stands for "table data," which is the
Table property
Tag Description
<col> Defines the attribute values for one or more columns in a table
Example 1:
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
Output:
Headings in a Table
<table border="1">
<tr>
<th>Heading</th>
<th>Another Heading</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
Output:
Heading Another Heading
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
Use rowspan to span multiple rows and colspan to span multiple columns.
<th>Column 1</th>
<th>Column 2</th>
</table>
Output
<tr>
<th>Column 1</th>
</table>
Output
Column 1 Column 2
HTML Frames
With frames, you can display more than one HTML document in the same browser
window. Each HTML document is called a frame, and each frame is independent of
the others.
The <frameset> tag defines how to divide the window into frames
Attribute Description
rows Specifies the number of rows and their height in either pixels, percentages, or
relative lengths. Default is 100%
cols Specifies the number of columns and their width in either pixels, percentages,
or relative lengths. Default is 100%
name Assigns a name to a frame. This is useful for loading contents into one frame
from another.
longdesc A long description - this can elaborate on a shorter description specified with
the title attribute.
src Location of the frame contents (for example, the HTML page to be loaded into
the frame).
noresize Specifies whether the frame is resizable or not (i.e. whether the user can resize
the frame or not).
scrolling Whether the frame should be scrollable or not (i.e. should scrollbars appear).
Possible values:
auto
yes
no
frameborder Whether the frame should have a border or not. Possible values:
1 (border)
0 (no border)
marginwidth Specifies the margin, in pixels, between the frame's contents and it's left and
right margins.
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 20
marginheight Specifies the margin, in pixels, between the frame's contents and it's top and
bottom margins.
Example 1
<frameset cols="25%,75%">
<frame src="frame_a.htm">
<html>
<frameset rows="50%,50%">
<frame src="frame_a.htm">
<frameset cols="25%,75%">
<frame src="frame_b.htm">
Style sheet
cascading style sheets are now the standard way to define the presentation of
your HTML pages, from fonts and colours to the complete layout of a page. They are
much more efficient than using HTML on every page to define the look of your site.
CSS is becoming a more important language to know every day, so the sooner
you have a grip on this most elegant of presentational languages, the better.
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
The property is the style attribute you want to change. Each property has a value.
CSS Example
CSS declarations always ends with a semicolon, and declaration groups are
surrounded by curly brackets:
<html> <head>
<style type="text/css">
P{
color:red;
text-align:center;
</style>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
CSS Background
background-color
background-image
background-repeat
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 22
background-attachment
background-position
Background Color
The background-color property specifies the background color of an element.
body {background-color:#b0c4de;}
Background Image
The background-image property specifies an image to use as the background of
an element.By default, the image is repeated so it covers the entire element.
body {background-image:url('paper.gif');
body
{ background-image:url('gradient2.png'); }
Text Color
The color property is used to set the color of the text. The color can be specified
by:
Example
body {color:blue;}
h1 {color:#00ff00;}
h2 {color:rgb(255,0,0);
text-shadow none
color
length
unicode-bidi normal
embed
bidi-override
In CSS, there are two types of font family names:generic family - a group of
font families with a similar look (like "Serif" or "Monospace")
font family - a specific font family (like "Times New Roman" or "Arial")
Example
Example Program
<html> <head>
p.normal {font-weight:normal;}
p.light {font-weight:lighter;}
p.thick {font-weight:bold;}
p.thicker {font-weight:900;}
</style></head>
<body>
</body></html>
List
ordered lists - the list items are marked with numbers or letters
Example
CSS has several options for defining colors of both text and background areas on your pages. These options can
entirely replace the color attributes in plain HTML. In addition, you get new options that you just didn't have in plain
HTML.
Value Description
color <color>
transparent
background-color
<color>
none
background-image
url(<URL>)
repeat
repeat-x
background-repeat
repeat-y
no-repeat
scroll
background-attachment
fixed
<percentage>
<length>
top
background-position center
bottom
left
right
background <background-color>
<background-image>
<background-repeat>
<background-attachment>
color <color>
transparent
background-color
<color>
none
background-image
url(<URL>)
repeat
repeat-x
background-repeat
repeat-y
no-repeat
Example Program
<html><head>
<style type="text/css">
body{
background-color:#d0e4fe;}
h1
color:orange;
text-align:center;
font-size:20px;
}</style></head>
<body>
<h1>CSS example!</h1>
<p>This is a paragraph.</p>
</body></html>
All HTML elements can be considered as boxes. In CSS, the term "box model" is used
when talking about design and layout.
The CSS box model is essentially a box that wraps around HTML elements, and it
consists of: margins, borders, padding, and the actual content.
The box model allows us to place a border around elements and space elements in
relation to other elements
Margin - Clears an area around the border. The margin does not have a background
color, and it is completely transparent
Border - A border that lies around the padding and content. The border is affected
by the background color of the box
Padding - Clears an area around the content. The padding is affected by the
background color of the box
Content - The content of the box, where text and images appear
Example:
<html><head>
<style type="text/css">
div.ex
width:220px;
padding:10px;
margin:0px;
</style></head>
</body>
</html>
The display property specifies if/how an element is displayed, and the visibility
property specifies if an element should be visible or hidden.
Example
h1.hidden {visibility:hidden;}
Changing an inline element to a block element, or vice versa, can be useful for
making the page look a specific way, and still follow web standards.
li {display:inline;}
Example
<html><head>
<style type="text/css">
Span {
display:block;
</style> </head>
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 31
<body>
<h2>Nirvana</h2>
<h2>Radiohead</h2>
<span>Record: OK Computer</span>
<span>Year: 1997</span></body></html>
UNIT – 2: JavaScript
Purpose
Provide an easy way to access cross-referenced documents that exist on the
internet .Purpose make web pages (documents) more dynamic and interactive
Change contents of document, provide forms and controls, animation, control web
browser window, etc.
Syntax
<html>
<body>
<script type="text/javascript">
//your script goes here
</script>
</body>
</html>
And
<script type="text/javascript" src=’path.js’> </script>
Mostly in the head section of HTML file, use script tags and then enclose in comments
Example:
<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
Elements of JavaScript
Variables
JavaScript is not a strongly typed language which means you rarely have to
concern yourself with the type of data a variable is storing, only what the variable is
storing and in JavaScript, variables can store anything, even functions.
Syntax : var <variable Name> =value
<html><body>
<script type="text/javascript">
x=5+5;
document.write(x);
document.write("<br />");
var a=5,b=10,c;
c=a+b;
document.write(c);
document.write("<br />");
var oct=0377,x=10,res;
res=oct+x;
document.write(res);
x=5+"5";
document.write(x);
document.write("<br />");
x="5"+5;
document.write(x);
document.write("<br />");
</script></body>
</html>
Array
Arrays are simply an ordered stack of data items with the same data type. Using
arrays, you can store multiple values under a single name. Instead of using a
separate variable for each item, you can use one array to hold all of them.
Syntax
<html>
<body>
<script type="text/javascript">
document.write(fruits.sort());
</script></body>
</html>
<html>
<body>
<script type="text/javascript">
function sortNumber(a, b)
return b - a;
document.write(n.sort(sortNumber));
</script></body>
</html>
Dynamic Arrays:
In many a cases we will not want to create the array with a fixed size or length.
In such cases we can create an array with out passing length. This array will
dynamically set its value as and when a new variable or entry is added
Looping Constructor
A set of statements are executed as a loop until a condition is satisfied, the condition
is based on an incremental or decremental counter. In other words "Looping
statements in javascript are used to execute the same set of code a specified number
of times"
If Statement
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 37
Use the if statement to execute some code only if a specified condition is true.
Syntax
if (condition)
{
code to be executed if condition is true
}
If...else Statement
Use the if....else statement to execute some code if a condition is true and another
code if the condition is not true.
Syntax
if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
Example
<html><body>
<script type="text/javascript">
var a=5,b=10;
if(a>b)
document.write("A is big");
}else
document.write("B is big");
Switch Statement:
Syntax
switch(n)
{
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
Example
<html><body>
<script type="text/javascript">
theDay=d.getDay()
switch (theDay)
case 1: document.write("SUNDAY")
break;
break;
break;
default:
while Loop
The while loop loops through a block of code while a specified condition is true.
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 39
Syntax
while (var<=endvalue)
{
code to be executed
}
Example
<html> <body>
<script type="text/javascript">
i=0
while (i <= 5)
document.write("<br>")
i++
do...while Loop
The do...while loop is a variant of the while loop. This loop will execute the block of
code ONCE, and then it will repeat the loop as long as the specified condition is true.
Syntax
do
{
code to be executed
}
while (var<=endvalue);
Example
<script language="javascript">
do
while(i!=0)
</script>
for Loop
The for loop is used when you know in advance how many times the script should
run.
Syntax
for(var=startvalue;var<=endvalue;var=var+increment)
{
code to be executed
}
Example
<html> <body>
<script type="text/javascript">
document.write("<br>")
Function
A function contains code that will be executed by an event or by a call to the function.
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 41
You may call a function from anywhere within a page (or even from other pages if the
function is embedded in an external .js file).
Functions can be defined both in the <head> and in the <body> section of a
document.
Syntax
function functionname(var1,var2,...,varX)
{
some code
}
Example
<html> <head>
<script type="text/javascript">
function myfunction(txt)
alert(txt)
</script>
</head>
<body>
<form>
</form>
</body> </html>
The return statement is used to specify the value that is returned from the function.
So, functions that are going to return a value must use the return statement.
Example
<head>
<script type="text/javascript">
function total(numberA,numberB)
</script>
</head>
<body>
<script type="text/javascript">
document.write(total(2,5))
</script>
</body>
</html>
Dialog box
JavaScript supports three important types of dialog boxes. These dialog boxes can be
used to raise and alert, or to get confirmation on any input or to have a kind of input
from the users.
The alert() method displays an alert box with a specified message and an OK button.
Syntax
alert(message)
Example
<html>
<head>
function display()
</script>
</head>
<body>
</body>
</html>
The prompt dialog box is very useful when you want to pop-up a text box to get user
input
Syntax
prompt(msg,defaultText)
Example
<html> <head>
<script type="text/javascript">
function dispprompt()
</script>
<body>
<div id="msg"></div>
</body>
</html>
A confirmation dialog box is mostly used to take user's consent on any option. It
displays a dialog box with two buttons: OK and Cancel.
Syntax
confirm(message)
Example
<html><head>
<script type="text/javascript">
function display()
</body> </html>
UNIT – 3
The Document object provides access to all HTML elements in a page, from within a
script.
The Document object is also part of the Window object, and can be accessed through the window.document
property.
Collection Description
Anchors
The anchors collection returns an array of all the anchors in the current document.
Syntax
document.anchors[].property
Example
<html>
<body>
<script type="text/javascript">
document.write(document.anchors.length);</script></p>
</body>
</html>
forms
Syntax
document.forms[].property
Example
<html>
<body>
<form name="Form1"></form>
<form name="Form2"></form>
<p>Number of forms:
<script type="text/javascript">
document.write(document.forms.length);
</script></p>
</body>
</html>
images
The images collection returns an array of all the images in the current document.
Syntax
document.images[].property
Example:
<html>
<body>
<img border="0" src="a.jpg" width="150" height="113" />
<img border="0" src="b.jpg" width="152" height="128" />
<p>Number of images:
<script type="text/javascript">
document.write(document.images.length);
</script></p></body> </html>
Links
The links collection returns an array of all the links in the current document.
The links collection counts
Javascript is an event driven language which means your scripts react to events you
set up. Your code isn't running all the time, it simply waits until an event starts
something up! Going into all the Javascript events is beyond the scope.
Syntax
window.open(URL,name,specs)
Reload window
To reload a window, use this method:
window.location.reload()
Close Window
The closed property returns a Boolean value indicating whether a window has been
closed or not.
Syntax
window.close()
<html>
<head>
<script type="text/javascript">
function openWin()
{
myWindow=window.open("","","width=200,height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
}
function closeWin()
{
myWindow.close();
}
function Relo()
{
myWindow.location.reload()
}
</script>
</head>
<body>
<input type="button" value="Open 'myWindow'" onclick="openWin()" />
<input type="button" value="Close 'myWindow'" onclick="closeWin()" />
<input type="button" value="Reload" onclick="Relo()" />
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 50
</body>
</html>
setInterval() method
The setInterval() method calls a function or evaluates an expression at specified
intervals (in milliseconds).
1000 ms = 1 second.
Syntax
setInterval(“windowname”,millisec)
Eg:
setTimeout("alert('hi!');", 500);
Navigator Object
The navigator object contains information about the browser.
Property Description
appCodeName Returns the code name of the browser
appName Returns the name of the browser
appVersion Returns the version information of the browser
cookieEnabled Determines whether cookies are enabled in the browser
Navigator Syntax
navigator.appCodeName
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 51
navigator.appName
navigator.appVersion
navigator.cookieEnabled
navigator.platform
navigator.userAgent
Example
<html>
<body>
<script type="text/javascript">
document.write("Browser CodeName: " + navigator.appCodeName);
document.write("<br /><br />");
document.write("Browser Name: " + navigator.appName);
document.write("<br /><br />");
document.write("Browser Version: " + navigator.appVersion);
document.write("<br /><br />");
document.write("Cookies Enabled: " + navigator.cookieEnabled);
document.write("<br /><br />");
document.write("Platform: " + navigator.platform);
document.write("<br /><br />");
document.write("User-agent header: " + navigator.userAgent);
</script></body>
</html>
Screen object
Screen Syntax
screen.availHeight
screen.availWidth
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 52
screen.colorDepth
screen.height
screen.pixelDepth
screen.width
Example
<HTML>
<BODY>
<script type="text/javascript">
document.write("Available Height: " + screen.availHeight);
document.write("</br>Available Width: " + screen.availWidth);
document.write("</br>Color Depth: " + screen.colorDepth);
document.write("</br>Total Height: " + screen.height);
document.write("</br>Color resolution: " + screen.pixelDepth);
document.write("</br>Total Width: " + screen.width);
</script>
</BODY>
</HTML>
Form Object
form object is a Browser object of JavaScript used to access an HTML form. If a user
wants to access all forms within a document then he can use the forms array.
The form object is actually a property of document object that is uniquely created by
the browser for each form present in a document.
The properties and methods associated with form object are used to access the form
fields, attributes and controls associated with forms.
action:
This property is a read or write property and its value is a string.
elements[]:
It contains all fields and controls present in the form. The user can access any
element associated with the form by using the looping concept on the elements array.
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 53
encoding:
This property is a read or write property and its value is a string. This property helps
determine the way of encoding the form data.
length:
This denotes the length of the elements array associated with the form.
method:
This property is a read or write property and its value is a string. This property helps
determine the method by which the form is submitted.
name:
name property of form object denotes the form name.
target:
This property denotes the name of the target window to which form it is to be
submitted into.
button:
The button property of form object denotes the button GUI control placed in the form.
checkbox:
checkbox property of form object denotes the checkbox field placed in the form.
select:
select property of form object denotes the selection list object placed in the form.
submit:
submit property of form object denotes the submit button field that is placed in the
form.
text:
text property of form object denotes the text field placed in the form.
textarea:
textarea property of form object denotes the text area field placed in the form.
<HTML>
<HEAD>
<TITLE>Test Input</TITLE>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="" METHOD="GET">Enter box: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" >
<br>
Genter
<INPUT TYPE="radio" NAME="rad" VALUE="radio_button3" onClick=0>
<INPUT TYPE="radio" NAME="rad" VALUE="radio_button4" onClick=0>
<br>Language know<br>
<INPUT TYPE="checkbox" NAME="check2" Value="Check2">Tamil<BR>
<INPUT TYPE="checkbox" NAME="check3" Value="Check3">English<BR>
</br>
This is Text Area
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 54
<TEXTAREA NAME="myarea" COLS="40" ROWS="5">
</TEXTAREA>
</br>
List Items
<SELECT NAME="list" SIZE="1">
<OPTION>This is item 1
<OPTION>This is item 2
</SELECT>
</br>
<FORM>
<INPUT TYPE="file" NAME="elementName">
</FORM>
</FORM>
</BODY>
</HTML>
Built-in objects
These built-in objects are available through both the client-side JavaScript and
through LiveWire (Netscape's server-side application).
The three built-in objects are: the String object, the Math object, and
the Date object. Each of these provides great functionality, and together they give
JavaScript its power as a scripting language.
The String Object
The String object is used to manipulate a stored piece of text.
String objects are created with new String().
Syntax
var txt = new String(string);
<html>
<body>
<script type="text/javascript">
var str="Hello world!";
document.write("First character: " + str.charAt(0) + "<br />");
document.write("Unicode of first character: " + str.charCodeAt(0) + "<br />");
document.write(str.indexOf("Hello") + "<br />");
document.write(str.toLowerCase()+"<br />");
document.write(str.toUpperCase()+"<br />");
document.write(str.valueOf()+"<br />")
var str1="Hello ";
var str2="Dharma!";
var str3=" Have a nice day!";
document.write(str1.concat(str2,str3)+ "<br />");
document.write(String.fromCharCode(72,69,76,76,79)+ "<br />");
document.write(str.lastIndexOf("Hello") + "<br />");
var str1="The rain in SPAIN stays mainly in the plain";
var patt1=/ain/gi;
document.write(str1.match(patt1)+ "<br />");
document.write(str.replace("Microsoft", "W3Schools"));
document.write(str.search("W3SCHOOLS"));
document.write(str.substr(3)+"<br />");
document.write(str.substr(3,4));
</script>
</body>
</html>
Date Object
Example
<html>
<body>
<script type="text/javascript">
var d=new Date()
document.write(d.getDate())
document.write(".")
document.write(d.getMonth() +1)
document.write(".")
document.write(d.getFullYear())
document.write(".")
document.write(d.getHours())
</script>
</body>
</html>
Math Object
Syntax
var x = Math.PI; // Returns PI
var y = Math.sqrt(16); // Returns the square root of 16
Property Description
Example
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 58
<html>
<body>
<script type="text/javascript">
document.write("abs"+Math.abs(7.25) + "<br />");
document.write("acos"+Math.acos(0.64) + "<br />")
document.write("asin"+Math.asin(0.64) + "<br />")
document.write("atan2"+Math.atan2(8,4)+ "<br />");
document.write("ceil"+Math.ceil(0.60) + "<br />");
document.write("cos"+Math.cos(3) + "<br />");
document.write("floor"+Math.floor(0.60) + "<br />")
document.write("log"+Math.log(1) + "<br />");
document.write("max"+Math.max(-5,10) + "<br />");
document.write("pow"+Math.pow(0,0) + "<br />");
document.write("rount"+Math.round(0.60) + "<br />");
document.write("random"+Math.random() + "<br />");
document.write("sin"+Math.sin(3) + "<br />");
document.write("sqrt"+Math.sqrt(9) + "<br />");
</script>
</body>
</html>
All user-defined objects and built-in objects are descendants of an object called
Object. .
The new Operator:
The new operator is used to create an instance of an object. To create an object,
the new operator is followed by the constructor method.
Example
<html>
<head>
<title>User-defined objects</title>
<script type="text/javascript">
var book = new Object(); // Create the object
book.subject = "C++"; // Assign properties to the object
book.author = "Balagurusami";
</script>
</head>
<body>
<script type="text/javascript">
document.write("Book name is : " + book.subject + "<br>");
document.write("Book author is : " + book.author + "<br>");
</script>
</body>
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 59
</html>
cookies
Cookies are small amounts of data stored by the web browser. They allow you to
store particular information about a user and retrieve it every time they visit your
pages.Each user has their own unique set of cookies.
syntax
name=value This sets both the cookie's name and its value.
Ex : username=AAAA
expires=date This optional value sets the date that the cookie will expire on. The
date should be in the format returned by the the toGMTString() method of
the Date object – Greenwith Mean Time(DD-MM-YY)
expires=13/06/2003 00:00:00
domain=domain This optional value specifies a domain within which the cookie
applies. Only websites in this domain will be able to retrieve the cookie
Ex : domain=google.com
secure : This optional flag indicates that the browser should use SSL when sending
the cookie to the server. This flag is rarely used.
Example
<html>
<head>
<script type="text/javascript">
<!--
function WriteCookie()
{
if( document.myform.customer.value == "" )
{
alert("Enter some value!");
return;
}
cookievalue= escape(document.myform.customer.value) + ";";
document.cookie="name=" + cookievalue;
alert("Setting Cookies : " + "name=" + cookievalue );
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 60
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
Enter name: <input type="text" name="customer"/>
<input type="button" value="Set Cookie" onclick="WriteCookie();"/>
</form>
</body>
</html>
Microsoft. NET
The Microsoft. NET strategy was presented by Microsoft officials to the rest of the
world in June 2000:
NET Framework
The .NET Framework is the infrastructure for the new Microsoft .NET Platform.
The .NET Framework is a common environment for building, deploying, and running
Web Services and Web Applications.
The .NET Framework contains common class libraries - like ADO.NET, ASP.NET and
Windows Forms - to provide advanced standard services that can be integrated into a
variety of computer systems.
The .NET Framework is language neutral. Currently it supports C++, C#, Visual
Basic, JScript (The Microsoft version of JavaScript) and COBOL. Third-party languages
- like Eiffel, Perl, Python, Smalltalk, and others - will also be available for building
future .NET Framework applications.
Compilers and tools expose the runtime's functionality and enable you to write code
that benefits from this managed execution environment. Code that you develop with
a language compiler that targets the runtime is called managed code; it benefits from
features such as cross-language integration, cross-language exception handling,
enhanced security, versioning and deployment support, a simplified model for
component interaction, and debugging and profiling services.
To enable the runtime to provide services to managed code, language compilers must
emit metadata that describes the types, members, and references in your code.
Metadata is stored with the code; every loadable common language runtime portable
executable (PE) file contains metadata. The runtime uses metadata to locate and load
classes, lay out instances in memory, resolve method invocations, generate native
code, enforce security, and set run-time context boundaries.
The runtime automatically handles object layout and manages references to objects,
releasing them when they are no longer being used. Objects whose lifetimes are
managed in this way are called managed data. Garbage collection eliminates memory
leaks as well as some other common programming errors. If your code is managed,
you can use managed data, unmanaged data, or both managed and unmanaged data
in your .NET Framework application. Because language compilers supply their own
types, such as primitive types, you might not always know (or need to know)
whether your data is being managed.
The common language runtime makes it easy to design components and applications
whose objects interact across languages. Objects written in different languages can
communicate with each other, and their behaviors can be tightly integrated. For
example, you can define a class and then use a different language to derive a class
from your original class or call a method on the original class. You can also pass an
instance of a class to a method of a class written in a different language. This cross-
language integration is possible because language compilers and tools that target the
runtime use a common type system defined by the runtime, and they follow the
runtime's rules for defining new types, as well as for creating, using, persisting, and
binding to types.
As part of their metadata, all managed components carry information about the
components and resources they were built against. The runtime uses this information
to ensure that your component or application has the specified versions of everything
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 63
it needs, which makes your code less likely to break because of some unmet
dependency. Registration information and state data are no longer stored in the
registry where they can be difficult to establish and maintain. Rather, information
about the types you define (and their dependencies) is stored with the code as
metadata, making the tasks of component replication and removal much less
complicated.
Language compilers and tools expose the runtime's functionality in ways that are
intended to be useful and intuitive to developers. This means that some features of
the runtime might be more noticeable in one environment than in another. How you
experience the runtime depends on which language compilers or tools you use. For
example, if you are a Visual Basic developer, you might notice that with the common
language runtime, the Visual Basic language has more object-oriented features than
before. Following are some benefits of the runtime:
Performance improvements.
The ability to easily use components developed in other languages.
If you use Microsoft Visual C++.NET, you can write managed code using the Managed
Extensions for C++, which provide the benefits of a managed execution environment
as well as access to powerful capabilities and expressive data types that you are
familiar with. Additional runtime features include:
The ability to compile once and run on any CPU and operating system that
supports the runtime.
The CLS is simply a specification that defines the rules to support language
integration in such a way that programs written in any language, yet can
interoperate with one another, taking full advantage of inheritance, polymorphism,
exceptions, and other features.
ASP.NET
ASP.NET is the latest version of ASP. It includes Web Services to link applications,
services and devices using HTTP, HTML, XML and SOAP.
New in ASP.NET:
User Authentication
High Scalability
Compiled Code
Easy Configuration
Easy Deployment
Includes ADO.NET
Asp.Net – Introduction
Asp.net is the new offering for Web developers form the Microsoft. It is not simply the
next generation of ASP. Because it has evolved from Asp, Asp.Net looks very similar
to its predecessor. But concepts like web forms, Web Services, or server controls
gives Asp.Net the power to build real Web application.
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 65
What is ASP.NET?
Web Applications are built using Web Forms. ASP.NET comes with built-in Web
Forms controls, which are responsible for generating the user interface. They
mirror typical HTML widgets like text boxes or buttons. If these controls do not
fit your needs, you are free to create your own user controls.
Features of ASP.NET
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 can be shared across Web farms,
and state information can be recovered, even if the server fails or the
connection breaks down
When an ASP.NET page runs, the page goes through a life cycle in which it performs a
series of processing steps. These include initialization, instantiating controls, restoring and
maintaining state, running event handler code, and rendering. It is important for you to
understand the page life cycle so that you can write code at the appropriate life-cycle stage
for the effect you intend. Additionally, if you develop custom controls, you must be familiar
with the page life cycle in order to correctly initialize controls, populate control properties
with view-state data, and run any control behavior code. (The life cycle of a control is based
on the page life cycle, but the page raises more events for a control than are available for an
ASP.NET page alone.)
In general terms, the page goes through the stages outlined in the following table. In addition to the
page life-cycle stages, there are application stages that occur before and after a request but are not specific
to a page.
Stage Description
Page request The page request occurs before the page life cycle begins. When the page is requested
by a user, ASP.NET determines whether the page needs to be parsed and compiled
(therefore beginning the life of a page), or whether a cached version of the page can be
sent in response without running the page.
Start In the start step, page properties such as Request and Response are set. At this stage,
the page also determines whether the request is a postback or a new request and sets
the IsPostBack property. Additionally, during the start step, the page's UICulture
property is set.
Page During page initialization, controls on the page are available and each control's
initialization UniqueID property is set. Any themes are also applied to the page. If the current
request is a postback, the postback data has not yet been loaded and control property
values have not been restored to the values from view state.
Load During load, if the current request is a postback, control properties are loaded with
information recovered from view state and control state.
Validation During validation, the Validate method of all validator controls is called, which sets the
Life-cycle Events
Within each stage of the life cycle of a page, the page raises events that you can handle to run your
own code. For control events, you bind the event handler to the event, either declaratively using
attributes such as onclick, or in code.
Pages also support automatic event wire-up, meaning that ASP.NET looks for methods with particular
names and automatically runs those methods when certain events are raised. If the
AutoEventWireup attribute of the @ Page directive is set to true (or if it is not defined, since by
default it is true), page events are automatically bound to methods that use the naming convention of
Page_event, such as Page_Load and Page_Init
The following table lists the page life-cycle events that you will use most frequently. There are more
events than those listed; however, they are not used for most page processing scenarios. Instead, they are
primarily used by server controls on the ASP.NET Web page to initialize and render themselves. If you want
to write your own ASP.NET server controls, you need to understand more about these stages.
If the request is a postback, the values of the controls have not yet been
restored from view state. If you set a control property at this stage, its value
might be overwritten in the next event.
Init Raised after all controls have been initialized and any skin settings have been
applied. Use this event to read or initialize control properties.
InitComplete Raised by the Page object. Use this event for processing tasks that require all
initialization be complete.
PreLoad Use this event if you need to perform processing on your page or control before the
Note
In a postback request, if the page contains validator controls, check the IsValid
property of the Page and of individual validation controls before performing any
processing.
LoadComplete Use this event for tasks that require that all other controls on the page be loaded.
PreRender Before this event occurs:
The Page object calls EnsureChildControls for each control and for the
page.
Each data bound control whose DataSourceID property is set calls its
DataBind method. For more information, see Data Binding Events for Data-
Bound Controls below.
The PreRender event occurs for each control on the page. Use the event to make
final changes to the contents of the page or its controls.
SaveStateComplete Before this event occurs, ViewState has been saved for the page and for all
controls. Any changes to the page or controls at this point will be ignored.
Use this event perform tasks that require view state to be saved, but that do not
make any changes to controls.
Render This is not an event; instead, at this stage of processing, the Page object calls this
method on each control. All ASP.NET Web server controls have a Render method
that writes out the control's markup that is sent to the browser.
If you create a custom control, you typically override this method to output the
control's markup. However, if your custom control incorporates only standard
ASP.NET Web server controls and no custom markup, you do not need to override
the Render method.
A user control (an .ascx file) automatically incorporates rendering, so you do not
need to explicitly render the control in code.
Unload This event occurs for each control and then for the page. In controls, use this event
to do final cleanup for specific controls, such as closing control-specific database
connections.
For the page itself, use this event to do final cleanup work, such as closing open files
and database connections, or finishing up logging or other request-specific tasks.
Note
During the unload stage, the page and its controls have been rendered, so you
cannot make further changes to the response stream. If you attempt to call a
method such as the Response.Write method, the page will throw an exception.
You can use directives to specify optional settings used by the page compiler when
processing ASP.NET files. For each directive you can set different attributes. One
example is the language directive at the beginning of a page defining the default
programming language.
Code declaration blocks are lines of code enclosed in <script> tags. They contain the runat=server
attribute, which tells ASP.NET that these controls can be accessed on the server and on the client.
Optionally you can specify the language for the block. The code block itself consists of the definition of
member variables and methods.
Render blocks contain inline code or inline expressions enclosed by the character sequences shown
here. The language used inside those blocks could be specified through a directive like the one shown
before.
You can declare several standard HTML elements as HTML server controls. Use the element as you are
familiar with in HTML and add the attribute runat=server. This causes the HTML element to be treated
as a server control. It is now programmatically accessible by using a unique ID. HTML server controls
must reside within a <form> section that also has the attribute runat=server.
There are two different kinds of custom controls. On the one hand there are the controls that ship with
.NET, and on the other hand you can create your own custom controls. Using custom server controls is
the best way to encapsulate common programmatic functionality.Just specify elements as you did with
HTML elements, but add a tag prefix, which is an alias for the fully qualified namespace of the control.
Again you must include the runat=server attribute. If you want to get programmatic access to the
control, just add an Id attribute.You can include properties for each server control to characterize its
behavior. For example, you can set the maximum length of a TextBox. Those properties might have
sub properties; you know this principle from HTML. Now you have the ability to specify, for example,
the size and type of the font you use .The last attribute is dedicated to event binding. This can be used
to bind the control to a specific event
You can create bindings between server controls and data sources. The data binding expression is
enclosed by the character sequences <%# and %>. The data-binding model provided by ASP.NET is
If you need to create an instance of an object on the server, use server-side object tags. When the
page is compiled, an instance of the specified object is created. To specify the object use the identifier
attribute. You can declare .NET objects using class as the identifier, and COM objects using either
progid or classid.
With server-side include directives you can include raw contents of a file anywhere in your ASP.NET
file. Specify the type of the path to filename with the path type attribute. Use either File, when
specifying a relative path, or Virtual, when using a full virtual path.
Server-side Comments
To prevent server code from executing, use these character sequences to comment it out. You can
comment out full blocks - not just single lines.
Asp.Net – Framework
ASP.NET is based on the fundamental architecture of .NET Framework. Visual studio provides a
uniform way to combine the various features of this Architecture. Architecture is explained form
bottom to top in the following discussion.
At the bottom of the Architecture is Common Language Runtime. NET framework common language
runtime resides on top of the operating system services. The common language runtime loads and
executes code that targets the runtime. This code is therefore called managed code. The runtime gives
you, for example, the ability for cross-language integration.
2. ADO.NET is Microsoft’s ActiveX Data Object (ADO) model for the .NET Framework. ADO.NET is not
simply the migration of the popular ADO model to the managed environment but a completely new
paradigm for data access and manipulation.
ADO.NET is intended specifically for developing web applications. This is evident from its two major
design principles:
>>Disconnected Datasets—In ADO.NET, almost all data manipulation is done outside the context of an
open database connection.
>>Effortless Data Exchange with XML—Datasets can converse in the universal data format of the Web,
namely XML.
3. The 4th layer of the framework consists of the Windows application model and, in parallel, the Web
application model.
The Web application model-in the slide presented as ASP.NET-includes Web Forms and Web Services.
ASP.NET comes with built-in Web Forms controls, which are responsible for generating the user
interface. They mirror typical HTML widgets like text boxes or buttons. If these controls do not fit your
needs, you are free to create your own user controls. Web Services brings you a model to bind
different applications over the Internet. This model is based on existing infrastructure and applications
and is therefore standard-based, simple, and adaptable. Web Services are software solutions delivered
via Internet to any device. Today, that means Web browsers on computers, for the most part, but the
device-agnostic design of .NET will eliminate this limitation.
4. One of the obvious themes of .NET is unification and interoperability between various programming
languages. In order to achieve this; certain rules must be laid and all the languages must follow these
rules. In other words we can not have languages running around creating their own extensions and
their own fancy new data types. CLS is the collection of the rules and constraints that every language
(that seeks to achieve .NET compatibility) must follow.
5.The CLR and the .NET Frameworks in general, however, are designed in such a way that code
written in one language can not only seamlessly be used by another language. Hence ASP.NET can be
programmed in any of the .NET compatible language whether it is VB.NET, C#, Managed C++ or
JScript.NET.
Asp.Net – Controls
Types of Controls:
1. Web Controls
2. Html Controls
3. Validation Controls
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 72
4. User Controls
1. Web Controls:
Web Controls provide a more consistent object model and a higher level of abstraction than
HtmlControls
– Most HTML elements can also be represented as Web Controls on the server
– Web Control versions typically have a more consistent interface (background color is always Back
Color property whereas in HTML it may be a style attribute (span) or a property (table) )
– Web Controls also provide higher-level controls with more functionality than primitive HTML
elements (like the Calendar control)
– Web Controls may render themselves differently based on client browser capabilities
Web controls
Button DropDownList
Calendar ListBox
CheckBox Panel
RadioButton Table
HyperLink TableRow
Textbox TableCell
<html>
<body>
<form runat="Server">
</body>
</html>
1.HTML Controls:
– Any HTML element in an ASPX page marked with the runat=server attribute will become an HTML
control on the server
– HTML elements with no distinguished server-side functionality (like div, span, etc.) are all
represented as HtmlGenericControl instances
Html Controls
HtmlInputFile HtmlButton
HtmlInputHidden HtmlSelect
HtmlInputRadioButton HtmlTable
HtmlInputText HtmlTableCell
HtmlInputButton HtmlTableRow
HtmlInputCheckButton HtmlTextArea
HtmlInputImage HtmlAnchor
HtmlAnchor
The Anchor control to programmatically control an <a> HTML element. The <a> HTML element
allows you to create a hyperlink that allows you to move to another location on the page or to another
Web page. The HtmlAnchor control must be well formed with an opening and closing tag.
HtmlButton Button control to program against the HTML <button> element. You can provide custom
code for the ServerClick event of the HtmlButtoncontrol to specify the action performed when the
control is clicked.
The HtmlButton control renders JavaScript to the client browser. The client browser must have
JavaScript enabled for this control to function properly
Declare an HtmlButton control on your Web Forms pag
HtmlForm
Form control to program against the HTML <form> element. To take advantage of the postback
services, all Web Forms controls, whether HTML, Web, pagelet, or custom, must be nested between
well-formed opening and closing tags of the HtmlForm control. If the tags are not closed properly,
ASP.NET will not recognize the element. The element will either be ignored or a compilation error will
occur, depending on how the element is formed.
HtmlTable
Table control to program against the HTML <table> element. An HtmlTable control is made up of
rows (represented by HtmlTableRowobjects) stored in the Rows collection of a table. Each row is made
up of cells (represented by HtmlTableCell objects) stored in the Cells collection of a row.
To create a table, first declare an HtmlTable control in the form on your page. Next,
place HtmlTableRow objects between the opening and closing tags of the HtmlTable control, one for
each row you want in your table. Once the rows of the table are defined,
declare HtmlTableCell objects between the opening and closing tags of each HtmlTableRow object
to create the cells of the row.
<tr>
<td></td>
</tr>
</table>
HtmlInputFile
File control to program against the HTML <input type=file> element. You can use
the HtmlInputFile control to easily design a page that allows users to upload binary or text files from
a browser to a directory that you designate on your Web server. File upload is enabled in all HTML 3.2
Label control
Used to display text in a set location on the page. Unlike static text, you can customize the displayed
text by setting the Text property.
Button control
The Button control allows you to create a push button on the Web Forms page. There are two types of
buttons that can be created. You can create either a submit button or a command button.
CheckBox control
The CheckBox control creates a check box on the Web Forms page that allows the user to switch
between a true or false state. You can specify the caption to display in the control by setting
the Text property. The caption can appear either on the right or left of the check box. Set
the TextAlignproperty to specify the side that the caption appears on.
HyperLink control
Use the HyperLink control to create a link that moves you to another page or location on the page.
Specify the page or location to link to by using theNavigateUrl property. The link can either be
displayed as text or an image. To display text, either set the Text property or simply place the text
between the opening and closing tags of the HyperLink control. To display an image, set
the ImageUrl property.
This control only displays an image. If you want the image to behave like a button or need to
determine the coordinates where the mouse pointer is clicked on the image, use
the ImageButton control.
RadioButton
The RadioButton server control creates a radio button on the Web Forms page. Specify the text to
display in the control by setting Text property. The text can appear either on the left or the right of
the radio button. Set TextAlign property to control the side that the text appears on. You can group
multiple radio buttons together if you specify the same GroupName for each RadioButton control.
Grouping radio buttons together will only allow a mutually exclusive selection from the group.
The TextBox server control is an input control that lets the user enter text. By default,
the TextMode property is set to SingleLine, which creates a text box with only one line. You can also
set the property to MultiLine or Password. MultiLine creates a text box with more than one
line. Password creates a single-line text box that masks the value entered by the user. The display
width of the text box is determined by its Columns property. If the text box is a multiline text box,
the display height is determined by theRows property.
CheckBoxList control
The CheckBoxList control creates a multiselection check box group that can be dynamically
generated using data binding. To specify items that you want to appear in the CheckBoxList control,
place a ListItem element for each entry between the opening and closing tags of
the CheckBoxList control.
DropDownList control
To specify the items that appear in the DropDownList control, place a ListItem element for each
entry between the opening and closing tags of theDropDownList control.
Example
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="a" Value="1"></asp:ListItem>
<asp:ListItem Text="b" Value="2"></asp:ListItem
</asp:RadioButtonList>
ImageButton control
Use the ImageButton control to display an image that responds to mouse clicks. Specify the image to
display in the control by setting the ImageUrlproperty.
Both the Click and Command events are raised when the ImageButton control is clicked.
Use the ListBox control to create a list control that allows single or multiple item selection. Use
the Rows property to specify the height of the control. To enable multiple item selection, set
the SelectionMode property to ListSelectionMode.Multiple.
To specify the items that you want to appear in the ListBox control, place a ListItem element for
each entry between the opening and closing tags of theListBox control.
The DataGrid control displays the fields of a data source as columns in a table. Each row in
the DataGrid control represents a record in the data source. The DataGrid control supports selection,
editing, deleting, paging, and sorting.
Syntex
<asp:DataGrid ID="DataGrid1" runat="server"> </asp:DataGrid>
Example
<Script Runat="Server">
Sub Page_Load
conNorthwind.Open()
dgrdEmployees.DataSource = cmdSelect.ExecuteReader()
dgrdEmployees.DataBind()
conNorthwind.Close()
End Sub
</Script>
<html><head><title>ExpertDataGrid.aspx</title></head>
Repeater control
The Repeater control is different from other data list controls in that it allows you to
place HTML fragments in its templates. This allows you to create a complex HTML
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 79
structure, such as a table. For example, to create a list within an HTML table, start
the table by placing the <table> tag in theHeaderTemplate. Next, create the rows
and columns of the table by placing <tr> tags, <td> tags, and data-bound items in
the ItemTemplate. If you want a different appearance for alternating items in the
table, create an AlternatingItemTemplate with the same contents as
the ItemTemplate, except with a different style specified. Finally, complete the table
by placing the </table> tag in the FooterTemplate.
<asp:Repeater id="Repeater1"
DataSource="<% databindingexpression %>"
runat=server>
<HeaderTemplate>
Header template HTML
</HeaderTemplate>
<ItemTemplate>
Item template HTML
</ItemTemplate>
<AlternatingItemTemplate>
Alternating item template HTML
</AlternatingItemTemplate>
<SeparatorTemplate>
Separator template HTML
</SeparatorTemplate>
<FooterTemplate>
Footer template HTML
</FooterTemplate>
<asp:Repeater>
Cookies Overview
Cookies provide a means in Web applications to store user-specific information. For example, when a
user visits your site, you can use cookies to store user preferences or other information. When the
user visits your Web site another time, the application can retrieve the information it stored earlier.
A cookie is a small bit of text that accompanies requests and pages as they go between the Web
server and browser. The cookie contains information the Web application can read whenever the user
visits the site.
For example, if a user requests a page from your site and your application sends not just a page, but
also a cookie containing the date and time, when the user's browser gets the page, the browser also
gets the cookie, which it stores in a folder on the user's hard disk.
Later, if user requests a page from your site again, when the user enters the URL the browser looks on
the local hard disk for a cookie associated with the URL. If the cookie exists, the browser sends the
cookie to your site along with the page request. Your application can then determine the date and time
that the user last visited the site. You might use the information to display a message to the user or
check an expiration date.
Cookies are associated with a Web site, not with a specific page, so the browser and server will
exchange cookie information no matter what page the user requests from your site. As the user visits
different sites, each site might send a cookie to the user's browser as well; the browser stores all the
cookies separately.
Cookies help Web sites store information about visitors. More generally, cookies are one way of
maintaining continuity in a Web application—that is, of performing state management. Except for the
brief time when they are actually exchanging information, the browser and Web server are
disconnected. Each request a user makes to a Web server is treated independently of any other
request. Many times, however, it's useful for the Web server to recognize users when they request a
page. For example, the Web server on a shopping site keeps track of individual shoppers so the site
can manage shopping carts and other user-specific information. A cookie therefore acts as a kind of
calling card, presenting pertinent identification that helps an application know how to proceed.
Cookies are used for many purposes, all relating to helping the Web site remember users. For
example, a site conducting a poll might use a cookie simply as a Boolean value to indicate whether a
user's browser has already participated in voting so that the user cannot vote twice. A site that asks a
user to log on might use a cookie to record that the user already logged on so that the user does not
have to keep entering credentials.
You can add cookies to the Cookies collection in a number of ways. The following example shows two
methods to write cookies:
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 81
Visual Basic
Response.Cookies("userName").Value = "patrick"
Response.Cookies("userName").Expires = DateTime.Now.AddDays(1)
ADO .NET
Most applications need data access at one point of time making it a crucial component when working
with applications. Data access is making the application interact with a database, where all the data is
stored. Different applications have different requirements for database access. ASP.NET uses ADO
.NET (Active X Data Object) as it's data access and manipulation protocol which also enables us to
work with data on the Internet.
Advantages of ADO.Net
OLEDB
The dot net framework data provider for OLEDB provides connectivity with the OLEDB supported
database management systems. It is the recommended middle tier for the SQL Server 6.5 or earlier
and Microsoft Access Database. It is a general data provider. You can also use it to connect with the
SQL Server or Oracle Database Management Systems. The classes for this provider are present in the
System.Data.OleDBClient namespace.
Dataset
The dataset is a disconnected, in-memory representation of data. It can be considered as a local copy
of the relevant portions of the database. The DataSet is persisted in memory and the data in it can be
manipulated and updated independent of the database. When the use of this DataSet is finished,
changes can be made back to the central database for updating. The data in DataSet can be loaded
Data Provider
The Data Provider is responsible for providing and maintaining the connection to the database. A
DataProvider is a set of related components that work together to provide data in an efficient and
performance driven manner. The .NET Framework currently comes with two DataProviders: the
SQL Data Provider which is designed only to work with Microsoft's SQL Server 7.0 or later and the
OleDb DataProvider which allows us to connect to other types of databases like Access and Oracle.
Each DataProvider consists of the following component classes:
A connection object establishes the connection for the application with the database. The command
object provides direct execution of the command to the database. If the command returns more than a
single value, the command object returns a DataReader to provide the data. Alternatively, the
DataAdapter can be used to fill the Dataset object. The database can be updated using the command
object or the DataAdapter.
The Connection object creates the connection to the database. Microsoft Visual Studio .NET provides
two types of Connection classes: the SqlConnection object, which is designed specifically to connect to
Microsoft SQL Server 7.0 or later, and the OleDbConnection object, which can provide connections to a
wide range of database types like Microsoft Access and Oracle. The Connection object contains all of
the information required to open a connection to the database.
The Command object is represented by two corresponding classes: SqlCommand and OleDbCommand.
Command objects are used to execute commands to a database across a data connection. The
Command objects can be used to execute stored procedures on the database, SQL commands, or
return complete tables directly. Command objects provide three methods that are used to execute
commands on the database:
ExecuteNonQuery: Executes commands that have no return values such as INSERT, UPDATE or
DELETE
ExecuteScalar: Returns a single value from a database query
ExecuteReader: Returns a result set by way of a DataReader object
Created by K.Dharmarajan M.Sc, M.Phil., Lecturer ,Vels’s College, Chennai-117 84
The DataReader Object
The DataReader object provides a forward-only, read-only, connected stream recordset from a
database. Unlike other components of the Data Provider, DataReader objects cannot be directly
instantiated. Rather, the DataReader is returned as the result of the Command object's ExecuteReader
method. The SqlCommand.ExecuteReader method returns a SqlDataReader object, and the
OleDbCommand.ExecuteReader method returns an OleDbDataReader object. The DataReader can
provide rows of data directly to application logic when you do not need to keep the data cached in
memory. Because only one row is in memory at a time, the DataReader provides the lowest overhead
in terms of system performance but requires the exclusive use of an open Connection object for the
lifetime of the DataReader.
The DataAdapter is the class at the core of ADO .NET's disconnected data access. It is essentially the
middleman facilitating all communication between the database and a DataSet. The DataAdapter is
used either to fill a DataTable or DataSet with data from the database with it's Fill method. After the
memory-resident data has been manipulated, the DataAdapter can commit the changes to the
database by calling the Update method. The DataAdapter provides four properties that represent
database commands:
SelectCommand
InsertCommand
DeleteCommand
UpdateCommand
When the Update method is called, changes in the DataSet are copied back to the database and the
appropriate InsertCommand, DeleteCommand, or UpdateCommand is executed.
Internet Information Services is used to make your computer a web server. If we want to
have a web server for developing dynamic website or want to publish website on our own
server then we install the IIS. IIS is used on windows plate form.
IIS takes request from user and executes the required files and sends result back to the user.
IIS server also provides the services of SMTP (Simple Mail Transport Protocol). We can send
emails using SMTP. FrontPage server extensions are also the part of IIS
IIS 7 is built on a modular architecture. Modules, also called extensions, can be added or
removed individually so that only modules required for specific functionality have to be
installed. IIS 7 includes native modules as part of the full installation. These modules are
individual features that the server uses to process requests and include the following:
HTTP modules - Used to perform tasks specific to HTTP in the request-processing pipeline,
such as responding to information and inquiries sent in client headers, returning HTTP errors,
and redirecting requests.
E-mail is one of the most common and reliable methods of communication for both personal and
business purposes. It also plays an important role in each and every Web site. This role will be in the
type of automated e-mails from the server after posting information from a form. You may have
noticed these types of e-mails while registering on a site.
The .NET Framework makes the task of sending email from a Web page relatively simple. In order to
send an email from an ASP.NET Web page you need to use the SmtpMail class found in
the System.Web.Mail namespace, which contains a static method Send.
We are using System.Web.Mail.SmtpMail to send email in dotnet 1.1 which is obsolete in 2.0.
The System.Net.Mail.SmtpClient Class will provide us the same feature as that of its predecessor.
Sending Email
The namespace that needs to be imported to send an email is the System.Web.Mail namespace. We
use the SmtpMail and MailMessage classes of this namespace for this purpose. The MailMessage class
provides properties and methods for constructing an email message
Using System.IO;
Using System.Web.Mail;
mm.Attachments.Add(ma);
SmtpMail.SmtpServer="mail.programmersheaven.com";
Because of ASP.NET’s improved object model, much of the functionality of the Request and
Response objects has been deprecated. There remain other uses for these objects. You can
work with cookies, redirect users, check browser capabilities and even send binary
information down the output stream.
QueryString
The QueryString collection is used to retrieve the variable values in the HTTP query string.
The HTTP query string is specified by the values following the question mark (?), like this:
The line above generates a variable named txt with the value "this is a query string test".
Query strings are also generated by form submission, or by a user typing a query into the
address bar of the browser.
Request.QueryString(variable)[(index)|.Count]
Form Collection
The Form collection is used to retrieve the values of form elements from a form that uses the
POST method.
Syntax
Request.Form(element)[(index)|.Count]
Example:
ServerVariables Collection
The ServerVariables collection is used to retrieve the server variable values.
Syntax
Request.ServerVariables (server_variable)
Example
Authentication is simply establishing the identity of the user. In the secure office building,
every person must have an ID badge. Each person who works in the building might be issued
a cardkey or badge to display, and a visitor might be asked to wear a temporary ID.
Syntax
<configuration>
<system.web>
<authentication
mode = " [ Windows | Forms | Passport | None ] ">
</authentication>
</system.web>
</configuration>
This can be a requirement because SSL increases the CPU load on the web server and can
limit scalability. Often you need SSL only for a small subset of an application. On the other
hand SSL is not the "CPU killer" as sometime stated. IIS6 also support SSL accelerators that
allow to off-load the crypto operations to specialized CPUs.
IMO - in many cases it is totally OK to enable SSL protection for the whole application which
will save you from some headaches. But if you want a partitioned application, you have to
take several things into account
In the case of Forms authentication, the requireSSL attribute also checks if the user is
logging in from an SSL connection before calling FormsAuthentication.SetAuthCookie
(something you have to check yourself if you are issuing tickets manually).