II Bba Web Tech (Even Sem)
II Bba Web Tech (Even Sem)
AVS
COLLEGE OF ARTS & SCIENCE
(AUTONOMOUS)
Attur Main Road, Ramalingapuram, Salem - 106.
(Recognized under section 2(f) & 12(B) of UGC Act 1956 and
Accredited by NAAC with 'A' Grade)
(Co - Educational Institution | Affiliated to Periyar University, Salem
ISO 9001 : 2015 Certified Institution)
[email protected] | www.avscollege.ac.in
Ph : 9426 29322, 94427 00205.
Study Material
Paper Name : WEB TECHNOLOGY
THEORY AND PRACTICE
1
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
SYLLABUS
UNIT - 1
Internet Basic–Introduction to HTML– List– Creating Table – linking document – frames –
graphics to HTML Doc- Creating simple static pages.
UNIT - 2
Introduction to JavaScript – Advantage of Java script – java script syntax –Data type– variable
–array –operator and expression – looping constructor – function – Dialog box.
UNIT – 3
Java Script document object model – introduction – object in HTML – event handling –
window object – browser object–form object–navigate or object–build in object–
Cookies.
UNIT – 4
ASP. NET: Language Structure – page structure – page event, properties - compiler
directives. HTML server controls – Anchor, Tables, Forms - Basic Web server controls–
label, textbox, button, image, links, check & Radio button, hyperlink.
UNIT – 5
Request and Response objects - Working with data – OLEDB connection class, Command
class Transaction class, data adaptor class, data set class. Security: Authentication, IP
Address, Secure by SSL & Client Certificates.
2
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
UNIT - 1
Internet Basic–Introduction to HTML– List– Creating Table – linking document – frames –
graphics to HTML Doc- Creating simple static pages.
Internet Basic
• The Internet is a global network that connects millions of private, public, academic,
business, and government devices.
• It allows users to access information, communicate, and share data across the world.
Internet Components
• Hardware: Physical devices such as routers, switches, and computers that make up the
Internet's infrastructure.
• Software: Programs and protocols (e.g., web browsers, email clients) that enable users
to interact with the Internet.
Types of Internet Connections
• Dial-up: An older, slower type of connection that uses telephone lines.
• Broadband: A high-speed Internet connection, typically via fiber optics, DSL, or
cable.
• Wi-Fi: Wireless Internet connection using radio waves.
• Mobile Data: Internet access through cellular networks (3G, 4G, 5G).
Internet Services
• Email: Sending and receiving electronic messages.
• World Wide Web (WWW): A collection of interconnected documents and
multimedia resources.
• File Sharing: Sharing documents, photos, and other files over the Internet.
• Social Media: Platforms like Facebook, Twitter, and Instagram for communication and
sharing content.
• Cloud Computing: Using the Internet to store and access data on remote servers
instead of local devices.
Internet Uses
• Communication: Email, video calls, instant messaging.
• Entertainment: Online streaming services, gaming, social media.
• Education: Access to online courses, research papers, and learning resources.
• Business: Online marketing, shopping, banking, and transactions.
3
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Introduction to HTML
HTML stands for Hyper Text Markup Language. It is the standard language used to create
and structure content on the web.
• HTML is a markup language, not a programming language, meaning it annotates text
to define how it is structured and displayed by web browsers.
• It forms the building blocks of all websites and is complemented by CSS for style and
JavaScript for interactivity.
HTML Page Structure
The basic structure of an HTML page is shown below. It contains the essential building-block
elements (i.e. doctype declaration, HTML, head, title, and body elements) upon which all
web pages are created.
• <!DOCTYPE html> – This is the document type declaration, not a tag. It declares that
the document is an HTML5 document.
• <html> – This is called the HTML root element. All other elements are contained
4
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
within it.
• <head> – The head tag contains the “behind the scenes” elements for a webpage.
Elements within the head aren’t visible on the front end of a webpage. Typical elements
inside the <head> include:
o <title>: Defines the title displayed on the browser tab.
o <meta>: Provides information like the character set or viewport settings.
o <link>: Links external stylesheets or resources.
o <style>: Embeds internal CSS styles.
o <script>: Embeds JavaScript for functionality.
• <title> – The title is what is displayed on the top of your browser when you visit a
website and contains the title of the webpage that you are viewing.
• <h2> – The <h2> tag is a second-level heading tag.
• <p>– The <p> tag represents a paragraph of text.
• <body> – The body tag is used to enclose all the visible content of a webpage. In other
words, the body content is what the browser will show on the front end.
An HTML document can be created using an HTML text editor. Save the text file using the
“.html” or “.htm” extension. Once saved as an HTML document, the file can be opened as a
webpage in the browser.
List in HTML
A list in HTML is a way to group and organize items or elements in a specific order or
without any particular order. Lists are used to display content in a structured manner, such as
a list of items, tasks, or steps.
Types of Lists in HTML
There are three main types of lists in HTML:
1. Unordered List (ul):
o An unordered list is used to group a collection of items where the order does not
matter.
o Items in this list are displayed with bullet points.
Example:
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Orange</li>
5
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
</ul>
Output:
o Apple
o Banana
o Orange
2. Ordered List (ol):
o An ordered list is used when the order of items matters (for example, steps in a
process).
o Items in this list are displayed with numbers or letters.
Example:
<ol>
<li>First Step</li>
<li>Second Step</li>
<li>Third Step</li>
</ol>
Output:
1.First Step
2.Second Step
3.Third Step
6
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
CSS: A stylesheet language used for designing the look and feel of a website.
EXAMPLE:
<html>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
7
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
OUTPUT :
Linking document
• You can click on a link and jump to another document.
• When you move the mouse over a link, the mouse arrow will turn into a little hand.
HTML Links
Syntax :
The HTML <a> tag defines a hyperlink. It has the following syntax:
<a href="url">link text</a>
• The most important attribute of the <a> element is the href attribute, which indicates
the link's destination.
• The link text is the part that will be visible to the reader.
• Clicking on the link text, will send the reader to the specified URL address.
Example
This example shows how to create a link to W3Schools.com:
<a href="https://www.w3schools.com/">Visit W3Schools.com!</a>
OUTPUT:
Visit W3Schools.com!
8
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Example :
Use target="_blank" to open the linked document in a new browser window or tab:
<a href="https://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
Frames in HTML
HTML <frame> tag (Not supported in HTML5)
• HTML <frame> tag define the particular area within an HTML file where another
HTML web page can be displayed.
• A <frame> tag is used with <frameset>, and it divides a webpage into multiple
sections or frames, and each frame can contain different web pages.
Syntax
< frame src = "URL" >
Following are some specifications about the HTML <frame> tag
Display Block
Usage Frames
9
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Example:
Create Vertical frames:
<!DOCTYPE html>
<html>
<head>
<title>Frame tag</title>
</head>
<frameset cols="25%,50%,25%">
<frame src="frame1.html" >
<frame src="frame2.html">
<frame src="frame3.html">
</frameset>
</html>
OUTPUT:
10
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
11
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
12
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
</head>
<body>
<h1>Drawing on Canvas</h1>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid
#000000;"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "blue";
ctx.fillRect(50, 20, 100, 50);
</script>
</body>
</html>
Output:
13
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
<h2>About Me</h2>
<p>Hello! I am learning web development, and this is my first static page.</p>
<h2>Image Example</h2>
<img src="C:\Users\mercy\OneDrive\Pictures\Screenshots\Screenshot 2024-06-07
162837.png" alt="Placeholder Image" width="300" height="200">
UNIT – 1
CHOOSE THE BEST ANSWER:
1. What does HTML stand for?
a) Hyperlinks and Text Markup Language
b) Hyper Text Markup Language
c) Home Tool Markup Language
d) Hyper Tool Machine Language
Answer: b) Hyper Text Markup Language
14
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
15
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
16
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
b) <p>
c) <section>
d) <header>
Answer: b) <p>
14. Which attribute is used to set the background color of a webpage in HTML?
a) bgcolor
b) color
c) background
d) style
Answer: a) bgcolor
15. How do you define a comment in HTML?
a) <!-- Comment -->
b) // Comment
c) /* Comment */
d) # Comment
Answer: a) <!-- Comment -->
Five-Mark Questions :
1. Explain the steps to create a simple HTML table.
2. Explain the basic structure of an HTML document with an example.
Ten-Mark Questions :
1. Explain the different types of lists in HTML with examples.
2. Discuss the use of frames in HTML and explain how to create a frame-based layout.
3. Explain the basic structure of an HTML document with an example.
4. Describe the process of linking documents in HTML with examples.
5. Discuss the role of graphics in HTML and explain how to add images to a webpage.
17
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
UNIT - 2
Introduction to JavaScript – Advantage of Java script – java script syntax –Data type– variable
–array –operator and expression – looping constructor – function – Dialog box.
Introduction to JavaScript
JavaScript is a versatile, dynamically typed programming language used for interactive web
applications, supporting both client-side and server-side development, and integrating
seamlessly with HTML, CSS, and a rich standard library.
• JavaScript is a single-threaded language that executes one task at a time.
• It is an Interpreted language which means it executes the code line by line.
• The data type of the variable is decided at run-time in JavaScript that’s why it is
called dynamically typed.
First Program: “Hello, World!”
A “Hello, World!” program is the simplest way to get started with any programming language.
Here’s how you can write one in JavaScript.
<html>
<head></head>
<body>
<h1>Check the console for the message!</h1>
<script>
// This is our first JavaScript program
console.log("Hello, World!");
</script>
</body>
</html>
In this example
• The<script> tag is used to include JavaScript code inside an HTML document.
• console.log() prints messages to the browser’s developer console. Open the browser
console to see the “Hello, World!” message.
18
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Advantages of JavaScript
1. Client-Side Execution:
o Runs directly in the user's browser, reducing server load and speeding up
responses.
2. Easy to Learn and Use:
o Simple syntax and structure make it beginner-friendly.
3. Platform Independence:
o Compatible with all major browsers and platforms.
4. Rich Interfaces:
o Enables interactive features like drag-and-drop, sliders, and animations.
5. Versatility:
o Can be used for both front-end and back-end development (e.g., with Node.js).
6. Dynamic Updates:
o Updates content dynamically without requiring a full page reload (AJAX).
7. Extensive Libraries and Frameworks:
o Supports powerful frameworks like React, Angular, and Vue.js for faster
development.
8. Community Support:
o A vast developer community ensures abundant resources, tools, and problem-
solving forums.
9. Reduced Server Load:
o Validation and processing can be handled on the client side, minimizing server
requests.
10. Integration with Other Technologies:
o Works seamlessly with HTML and CSS to create complete web applications.
JavaScript Syntax
JavaScript syntax refers to the set of rules that define how JavaScript programs are written and
interpreted. Below are the key elements of JavaScript syntax:
1. Variables
• Variables store data values.
let x = 5; // ES6 (preferred)
var y = 10; // Older version
19
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
2. Data Types
• JavaScript supports several data types:
o Numbers: let num = 10;
o Strings: let name = "John";
o Booleans: let isActive = true;
o Objects: let person = { firstName: "John", lastName: "Doe" };
o Arrays: let fruits = ["Apple", "Banana", "Cherry"];
3. Operators
• Arithmetic: +, -, *, /, %
• Assignment: =, +=, -=, *=, /=
• Comparison: ==, ===, !=, <, >, <=, >=
• Logical: &&, ||, !
4. Comments
• Single-line: // This is a comment
• Multi-line:
/* This is a
multi-line comment */
5. Functions
• Functions are blocks of reusable code.
function greet(name) {
return "Hello, " + name;
}
console.log(greet("Alice")); // Output: Hello, Alice
6. Conditionals
• Used for decision-making.
if (x > 10) {
console.log("x is greater than 10");
} else {
20
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
7. Loops
• Perform repetitive tasks.
for (let i = 0; i < 5; i++) {
console.log(i);
}
8. Events
• Respond to user actions.
document.getElementById("btn").addEventListener("click", function() {
alert("Button clicked!");
});
9. Objects
• Store key-value pairs.
let car = {
make: "Toyota",
model: "Camry",
year: 2021
};
console.log(car.make); // Output: Toyota
21
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
For example:
1. var a=40;//holding number
2. var b="Rahul";//holding string
JavaScript primitive data types
There are five types of primitive data types in JavaScript. They are as follows:
22
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Variable
A JavaScript variable is simply a name of storage location. The actual value of a
variable can be changed at any time. Variables are helpful in various situations such as:
o Variables as Placeholders for unknown values: They can be used in places where
the values they represent are unknown when the code is written.
o Variables as Code Clarifies: They can make the purpose of your code cleaner.
Rules of naming variables in JavaScript:
There are some rules while declaring a JavaScript variable (also known as identifiers).
1. Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.
2. After first letter we can use digits (0 to 9), for example value1.
3. JavaScript variables are case sensitive, for example x and X are different variables.
In JavaScript, variables are used to store data values. There are three ways to declare a variable:
1. var
• Scope: Global or function-scoped.
• Hoisting: Variables declared with var are hoisted (declared but not initialized).
• Re-declaration: Can be re-declared within the same scope.
Example:
var name = "John"; // Declare and initialize variable
console.log(name); // Output: John
2. let
• Scope: Block-scoped (only accessible within the block it is defined).
• Hoisting: Variables declared with let are hoisted, but not initialized.
• Re-declaration: Cannot be re-declared within the same scope.
Example:
let age = 25; // Declare and initialize variable
console.log(age); // Output: 25
3. const
• Scope: Block-scoped (similar to let).
• Hoisting: Variables declared with const are hoisted, but not initialized.
• Re-declaration: Cannot be re-declared within the same scope.
23
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
• Immutability: Cannot reassign the value of a const variable, though objects and arrays
declared with const can have their contents modified.
Example:
const birthYear = 1996; // Declare and initialize variable
console.log(birthYear); // Output: 1996
Array in JavaScript
An array is a special variable in JavaScript used to store multiple values in a single
variable. Arrays are ordered collections of values, where each value (element) is assigned an
index.
Declaring an Array
You can declare an array in JavaScript in two ways:
1. Using Square Brackets ([])
let fruits = ["Apple", "Banana", "Cherry"];
2. Using the Array Constructor
let fruits = new Array("Apple", "Banana", "Cherry");
24
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Array Methods
JavaScript provides various built-in methods for manipulating arrays. Some of the common
methods include:
• push(): Adds an element to the end of the array.
let fruits = ["Apple", "Banana"];
fruits.push("Cherry");
console.log(fruits); // Output: ["Apple", "Banana", "Cherry"]
25
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Multi-Dimensional Arrays
JavaScript arrays can also contain other arrays, creating multi-dimensional arrays
(arrays within arrays).
Example:
let matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
console.log(matrix[0][1]); // Output: 2
Array Iteration
You can iterate through an array using loops:
for loop:
let fruits = ["Apple", "Banana", "Cherry"];
for (let i = 0; i < fruits.length; i++) {
console.log(fruits[i]);
}
forEach() method:
fruits.forEach(function(fruit) {
console.log(fruit);
});
1. Operators in JavaScript
Operators in JavaScript are special symbols used to perform operations on variables and values.
There are several types of operators based on their functionality.
Types of Operators
1. Arithmetic Operators
Used to perform basic arithmetic operations.
+ (Addition): Adds two values.
26
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
2. Assignment Operators
Used to assign values to variables.
=: Assigns a value to a variable.
let x = 10; // x is assigned the value 10
+=: Adds the right operand to the left operand and assigns the result to the left
operand.
let y = 5;
y += 3; // y = 8
-=: Subtracts the right operand from the left operand and assigns the result to the left
operand.
let z = 10;
z -= 4; // z = 6
*=: Multiplies the left operand by the right operand and assigns the result to the left
operand.
let p = 5;
p *= 2; // p = 10
/=: Divides the left operand by the right operand and assigns the result to the left
operand.
27
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
let q = 8;
q /= 4; // q = 2
3. Comparison Operators
Used to compare two values.
==: Equal to (value comparison).
5 == 5 // true
===: Strict equal to (value and type comparison).
5 === 5 // true
"5" === 5 // false
!=: Not equal to.
5 != 3 // true
!==: Strict not equal to (value and type comparison).
5 !== '5' // true
>: Greater than.
5 > 3 // true
<: Less than.
3 < 5 // true
>=: Greater than or equal to.
5 >= 5 // true
<=: Less than or equal to.
3 <= 5 // true
4. Logical Operators
Used to combine conditional statements.
&& (Logical AND): Returns true if both operands are true.
true && false // false
|| (Logical OR): Returns true if at least one operand is true.
true || false // true
! (Logical NOT): Reverses the logical state of its operand.
!true // false
28
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
2. Expressions in JavaScript
An expression is a combination of variables, operators, and values that produces a result.
• Arithmetic Expression: Combines numbers and operators to perform arithmetic
operations.
let result = 5 + 3 * 2; // result = 11
• Logical Expression: Combines values with logical operators (&&, ||, !).
let isTrue = (5 > 3) && (2 < 4); // isTrue = true
• String Expression: Combines strings and operators to concatenate text.
let message = "Hello" + " " + "World"; // message = "Hello World"
• Conditional Expression: Returns a value based on a condition.
let status = (age >= 18) ? "Adult" : "Minor"; // status = "Adult"
Summary
• Operators are used to perform operations on values.
• Expressions are combinations of values, variables, and operators that evaluate to a
result.
1. for Loop
The for loop is used to run a block of code a certain number of times, with a defined starting
point, condition, and increment/decrement step.
Syntax:
for (initialization; condition; increment) {
// code to be executed
}
Example:
for (let i = 0; i < 5; i++) {
console.log(i); // Prints numbers 0 to 4
29
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
}
• Initialization: let i = 0; initializes the loop variable.
• Condition: i < 5 is checked before every iteration. If true, the loop continues.
• Increment: i++ increases the value of i by 1 after each iteration.
2. while Loop
The while loop executes a block of code as long as the condition is true. It checks the condition
before each iteration.
Syntax:
while (condition) {
// code to be executed
}
Example:
let i = 0;
while (i < 5) {
console.log(i); // Prints numbers 0 to 4
i++; // Increment the value of i
}
• Condition: i < 5 is checked before each iteration.
• The loop continues running as long as the condition remains true.
3. do...while Loop
The do...while loop is similar to the while loop, but it checks the condition after executing the
block of code, ensuring that the code is executed at least once.
Syntax:
do {
// code to be executed
} while (condition);
Example:
let i = 0;
do {
console.log(i); // Prints numbers 0 to 4
i++;
} while (i < 5);
30
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
4. for...in Loop
The for...in loop is used to iterate over the properties of an object (or indices of an array).
Syntax:
for (let key in object) {
// code to be executed
}
Example:
let person = { name: "Alice", age: 25, city: "New York" };
for (let key in person) {
console.log(key + ": " + person[key]); // Prints the keys and values of the object
}
• key: The variable represents the property name of the object.
5. for...of Loop
The for...of loop is used to iterate over the values in an array or other iterable objects (like
strings).
Syntax:
for (let value of iterable) {
// code to be executed
}
Example:
let arr = [10, 20, 30, 40];
for (let num of arr) {
console.log(num); // Prints 10, 20, 30, 40
}
• value: Represents each element in the array or iterable object.
31
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
3. do...while loop: Ensures that the code inside the loop is executed at least once.
4. for...in loop: Iterates over the properties of an object.
5. for...of loop: Iterates over values in an iterable (like arrays or strings).
Function in JavaScript
A function is a block of code that performs a specific task. Functions help in organizing
code, making it reusable and easier to manage.
1. Defining a Function
Functions in JavaScript can be defined in the following way:
Syntax:
function functionName(parameters) {
// code to be executed
}
Example:
function greet(name) {
console.log("Hello, " + name);
}
32
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
3. Function Expression
A function can be assigned to a variable, creating a function expression.
Syntax:
let functionName = function(parameters) {
// code to be executed
};
Example:
let square = function(x) {
return x * x;
};
console.log(square(4)); // Output: 16
• The function is now stored in the variable square.
4. Arrow Functions
Arrow functions provide a shorter syntax for writing functions. They are often used for
anonymous functions.
Syntax:
const functionName = (parameters) => {
// code to be executed
}
Example:
const multiply = (a, b) => a * b;
5. Function Arguments
33
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Functions can take any number of arguments, and the arguments can be optional.
Example:
function sayHello(name = "Guest") {
console.log("Hello, " + name);
}
6. Anonymous Functions
Anonymous functions are functions that do not have a name. They are often used as arguments
to other functions.
Example:
setTimeout(function() {
console.log("This is an anonymous function");
}, 1000);
• setTimeout() is a JavaScript function that takes an anonymous function and a time
delay as arguments.
7. Function Scope
Functions have their own scope, meaning variables declared inside a function are not accessible
outside the function.
Example:
function testScope() {
let insideVar = "I am inside";
console.log(insideVar); // Output: I am inside
}
testScope();
console.log(insideVar); // Error: insideVar is not defined
• Variables inside a function cannot be accessed from outside.
34
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Summary of Functions:
1. Defining a function: Use the function keyword followed by a name and parameters.
2. Return values: Functions can return values using the return statement.
3. Function expression: Functions can be assigned to variables.
4. Arrow functions: A shorter syntax for defining functions.
5. Function arguments: Functions can take arguments, with optional default values.
6. Anonymous functions: Functions without a name, often used as arguments.
7. Scope: Variables declared within a function are not accessible outside it.
1. alert()
The alert() method is used to display a simple message box with a message and an "OK" button.
Syntax:
alert("Message");
Example:
alert("Hello, welcome to our website!");
• Purpose: To show messages, warnings, or errors to the user.
• Behavior: The dialog box must be dismissed by clicking "OK" before continuing with
any other actions on the webpage.
2. confirm()
The confirm() method presents the user with a dialog box containing a message, along with
two buttons: "OK" (true) and "Cancel" (false). This is used to ask for user confirmation.
Syntax:
let result = confirm("Are you sure?");
Example:
let isSure = confirm("Do you want to delete this file?");
if (isSure) {
35
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
alert("File deleted.");
} else {
alert("File not deleted.");
}
• Returns: true if the user clicks "OK" and false if the user clicks "Cancel."
• Purpose: To ask for confirmation from the user before performing an action (e.g.,
deleting something).
3. prompt()
The prompt() method is used to ask the user for input. It displays a dialog box with a message
and a text input field, allowing the user to type in a response.
Syntax:
let userInput = prompt("Please enter your name:");
Example:
let name = prompt("What is your name?");
alert("Hello, " + name);
• Returns: The string the user enters. If the user clicks "Cancel," it returns null.
• Purpose: To collect input from the user.
Key Differences:
1. alert(): Used for displaying information (no input).
2. confirm(): Used for asking yes/no questions.
3. prompt(): Used for getting input from the user.
36
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
These dialog boxes are useful for simple interaction with users but may interrupt the flow of
the webpage. For more complex interactions, you might consider using HTML forms or custom
modal windows.
UNIT – 2
CHOOSE THE BEST ANSWER:
1. What does HTML stand for?
a) Hyperlinks and Text Markup Language
b) Hyper Text Markup Language
c) Home Tool Markup Language
d) Hyper Tool Machine Language
Answer: b) Hyper Text Markup Language
2. Which HTML tag is used to create an ordered list?
a) a)
b) b)
c) c)
d)
Answer: b)
3. Which attribute is used to provide a hyperlink in an HTML document?
a) src
b) href
c) link
d) url
Answer: b) href
4. Which tag is used to insert an image in an HTML document?
a) a)
b) b)
c) c)
d)
Answer: a)
5. What is the purpose of the tag in HTML?
a) To define a table
b) To create frames for dividing the browser window
37
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
c) To include multimedia
d) To link documents
Answer: b) To create frames for dividing the browser window
6. What is the correct syntax to write a JavaScript variable?
a) variable x;
b) var x;
c) x variable;
d) int x;
Answer: b) var x;
7. Which data type is NOT supported in JavaScript?
a) String
b) Number
c) Boolean
d) Character
Answer: d) Character
8. Which JavaScript method is used to display a dialog box with a message and a
text box for user input?
a) alert()
b) confirm()
c) prompt()
d) message()
Answer: c) prompt()
9. What is the correct syntax to create a function in JavaScript?
a) function myFunction {}
b) function: myFunction {}
c) function myFunction() {}
d) function = myFunction()
Answer: c) function myFunction() {}
10. Which of the following is a looping construct in JavaScript?
a) if-else
b) for
c) switch
d) case
Answer: b) for
38
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
39
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
40
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
UNIT – 3
Java Script document object model – introduction – object in HTML – event handling –
window object – browser object–form object–navigate or object–build in object–
Cookies.
41
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Syntax: document.querySelectorAll("selector")
Example:
var items = document.querySelectorAll(".item");
items.forEach(item => {
item.style.color = "blue";
});
DOM Manipulation
• Change HTML content: You can change the content of an HTML element.
document.getElementById("demo").innerHTML = "New Content!";
• Change HTML attributes: You can change attributes of elements (e.g., src of an
image).
document.getElementById("myImage").src = "newImage.jpg";
• Add/Remove elements: You can add or remove elements in the DOM.
var newDiv = document.createElement("div");
newDiv.innerHTML = "New element added!";
document.body.appendChild(newDiv);
DOM Events
The DOM allows JavaScript to interact with events (like clicks, keypresses).
Example: Adding an event listener to a button.
document.getElementById("myButton").addEventListener("click", function() {
alert("Button clicked!");
});
Example: Using the DOM
Here’s an example of how the DOM can be used to manipulate a webpage:
HTML:
<!DOCTYPE html>
<html>
<body>
<h1 id="heading">Welcome to JavaScript DOM</h1>
<button id="changeButton">Change Text</button>
<p id="demo">This is a paragraph.</p>
</body>
</html>
JavaScript:
42
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
document.getElementById("changeButton").onclick = function() {
document.getElementById("demo").innerHTML = "Text changed!";
document.getElementById("heading").style.color = "red";
};
In this example:
• When the button is clicked, the text inside the paragraph (<p>) changes.
• The color of the heading (<h1>) changes to red.
• The DOM is a powerful tool for JavaScript to interact with and manipulate web
pages.
• By using DOM methods, you can easily modify the content, structure, and style of a
webpage in real-time.
Introduction - Objects in HTML
What are Objects in HTML?
• HTML objects are elements or parts of an HTML document that you can interact
with and manipulate using JavaScript.
• HTML elements like <div>, <p>, <input>, <form>, and <img> are treated as objects
in JavaScript, which means they have properties and methods that can be accessed
and modified.
HTML Object Model
• The HTML Object Model (HOM) is a structured representation of HTML elements
as objects.
• Each HTML element becomes an object that can be manipulated, styled, and
interacted with.
• The Document Object Model (DOM) is the actual interface that allows JavaScript to
access and control these HTML objects.
Properties of HTML Objects
HTML objects have properties that describe various aspects of the element. For example:
• innerHTML: Represents the content inside an HTML element.
• style: Contains the inline CSS styles of an element.
• value: For form elements (like <input>), it represents the current value or user input.
Example:
<p id="demo">This is a paragraph.</p>
JavaScript:
var para = document.getElementById("demo");
43
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
JavaScript:
var content = document.getElementById("content");
content.style.color = "blue"; // Change the text color to blue
JavaScript:
44
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
function changeName() {
document.getElementById("name").value = "Jane Smith"; // Change the input value
}
HTML Image as an Object
Images are also treated as objects, allowing you to manipulate them using JavaScript.
Example:
<img id="myImage" src="image1.jpg" alt="Image">
<button onclick="changeImage()">Change Image</button>
JavaScript:
function changeImage() {
document.getElementById("myImage").src = "image2.jpg"; // Change image source
}
45
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
<script>
// Select the button element
var button = document.getElementById("myButton");
<script>
var text = document.getElementById("hoverText");
46
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
// Change the text color when mouse is hovered over the paragraph
text.addEventListener("mouseover", function() {
text.style.color = "blue";
});
// Change the text color back when mouse leaves the paragraph
text.addEventListener("mouseout", function() {
text.style.color = "black";
});
</script>
Keyboard Events
JavaScript can handle keyboard events like key presses and key releases.
Example: Keypress Event
<input type="text" id="inputBox" placeholder="Type something...">
<script>
var input = document.getElementById("inputBox");
// Display an alert when any key is pressed inside the input box
input.addEventListener("keydown", function(event) {
alert("Key pressed: " + event.key);
});
</script>
Form Events
Form events occur when interacting with form elements like text fields, checkboxes,
and buttons.
Example: Submit Event
<form id="myForm">
<input type="text" placeholder="Enter your name">
<button type="submit">Submit</button>
</form>
47
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
<script>
var form = document.getElementById("myForm");
Event Object
When an event occurs, it triggers an event object, which contains useful information
about the event.
Example: Using the Event Object
<button id="clickButton">Click Me</button>
<script>
var button = document.getElementById("clickButton");
button.addEventListener("click", function(event) {
alert("You clicked at position: X = " + event.clientX + ", Y = " + event.clientY);
});
</script>
• The event object contains properties like clientX and clientY, which tell the position
of the mouse when the event occurred.
<script>
var button = document.getElementById("removeButton");
48
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
49
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
<script>
var form = document.getElementById("myForm");
50
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
51
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
• Math Object:
alert(Math.random()); // Returns a random number between 0 and 1
• Date Object:
var currentDate = new Date();
alert(currentDate); // Displays current date and time
NOTES:
• Window Object: Represents the browser window and provides methods for
interacting with the window.
• Browser Object: Provides information about the browser’s environment, such as
browser name, version, and language.
• Form Object: Represents HTML forms and provides methods to manipulate form
elements and submit the form.
• Navigator Object: Provides information about the browser, device, and user
environment (e.g., online status, language, platform).
• Built-in Objects: Include objects like String, Array, Math, Date, and RegExp that
help perform various common operations in JavaScript.
Cookies in JavaScript
Introduction to Cookies
• Cookies are small text files that are stored on the user's device (browser) when they
visit a website.
• They help in storing information that can be retrieved and sent back to the server
during subsequent requests.
• Cookies can store data like user preferences, session information, and more.
Why Cookies Are Used
• Session Management: To store user login status or other session-related data.
• User Preferences: Storing user-selected settings like theme, language, etc.
• Tracking: Cookies can track user activity on a website, for example, for analytics or
advertisements.
Creating Cookies in JavaScript
Cookies are created by assigning a string to the document.cookie property.
Syntax:
document.cookie = "key=value; expires=date; path=path; domain=domain; secure";
• key=value: The name and value of the cookie.
52
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
• expires=date: Specifies when the cookie will expire. If not set, it becomes a session
cookie (deleted when the browser closes).
• path: Specifies the URL path where the cookie is accessible.
• domain: Specifies the domain for which the cookie is valid.
• secure: Ensures the cookie is only sent over HTTPS connections.
Example:
document.cookie = "username=JohnDoe; expires=Thu, 18 Jan 2025 12:00:00 UTC; path=/";
Reading Cookies
You can read cookies using document.cookie. It returns all cookies in a single string.
Example:
var cookies = document.cookie;
console.log(cookies); // Output: "username=JohnDoe; theme=dark"
Accessing Specific Cookies
Since document.cookie returns all cookies in one string, you need to parse it to extract a
specific cookie.
Example:
function getCookie(name) {
var cookieArr = document.cookie.split(";");
for (var i = 0; i < cookieArr.length; i++) {
var cookie = cookieArr[i].trim();
if (cookie.indexOf(name + "=") === 0) {
return cookie.substring(name.length + 1);
}
}
return null;
}
53
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Deleting Cookies
To delete a cookie, set its expires attribute to a past date.
Example:
document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/";
Security and Limitations of Cookies
• Size Limit: Cookies are limited to around 4 KB of data.
• Security: If not handled properly, cookies can be vulnerable to security risks like theft
or manipulation. Use the secure attribute to ensure cookies are only sent over HTTPS
connections.
• Privacy: Be cautious when using cookies to track user behavior. Always follow
privacy guidelines and inform users.
Common Use Cases for Cookies
1. Login Sessions: Storing user authentication information.
2. User Preferences: Storing settings like theme or language.
3. Tracking and Analytics: Storing user activity for analytics purposes.
NOTE:
• Cookies are small pieces of data that help in storing user-specific information in the
browser.
• In JavaScript, you can create, read, update, and delete cookies using document.cookie.
• While cookies are useful for many purposes like session management and
personalization, it is important to handle them securely and responsibly.
54
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
UNIT – 3
CHOOSE THE BEST ANSWER:
What is used to store small pieces of data in a user's browser?
a) Cookies
b) Local Storage
c) Session Storage
d) Cache
Answer: a) Cookies
Which method allows you to access an element by its ID in JavaScript?
a) getElementById()
b) querySelector()
c) getElementsByClassName()
d) getElementsByTagName()
Answer: a) getElementById()
Which object is the global object in the browser environment?
a) Window
b) Document
c) Navigator
d) Form
Answer: a) Window
Which event occurs when a mouse button is clicked on an element?
a) click
b) mouseover
c) keydown
d) submit
Answer: a) click
Which method is used to read all cookies in JavaScript?
a) document.cookies
b) document.cookie
c) getCookie()
d) cookie.get()
Answer: b) document.cookie
What does the 'expires' attribute in a cookie specify?
a) When the cookie will expire
55
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
56
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Five-Mark Questions:
1. Explain the Document Object Model (DOM) and its structure.
2. What is the purpose of the getElementById() method in JavaScript?
3. What is an event listener, and how is it used in JavaScript?
4. Describe the process of creating a cookie in JavaScript.
5. How can you delete a cookie in JavaScript?
57
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Ten-Mark Questions:
1. Explain the methods and properties of the Window object in JavaScript.
2. What are cookies in JavaScript, and how are they used for session management?
3. Discuss the differences between getElementById() and querySelector() methods.
4. Explain how event handling works in JavaScript, with examples of mouse and
keyboard events.
5. Describe the process of creating, reading, and deleting cookies in JavaScript.
58
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
UNIT – 4
ASP. NET: Language Structure – page structure – page event, properties - compiler
directives.
HTML server controls – Anchor, Tables, Forms - Basic Web server controls–label, textbox,
button, image, links, check & Radio button, hyperlink.
ASP. NET:
Introduction to ASP.NET
ASP.NET is a web development framework created by Microsoft. It is used to build
dynamic web applications, websites, and services. It runs on the .NET Framework or
.NET Core and uses languages like C#, VB.NET, or F#.
What is ASP.NET?
1. ASP.NET stands for Active Server Pages .NET.
2. It allows developers to create websites that are:
o Dynamic: Content changes based on user actions.
o Data-driven: Connects to databases.
o Interactive: Supports user input and processing.
59
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
60
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
<html>
<head>
<title>ASP.NET Page Structure</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Welcome!"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click"
/>
</form>
</body>
</html>
(b) Code-Behind (Default.aspx.cs)
Contains server-side logic in C# or VB.NET. Example:
using System;
61
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
62
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
5. Page_Unload:
o Called when the page is unloaded from memory.
protected void Page_Unload(object sender, EventArgs e)
{
// Cleanup code
}
Summary
• Language Structure: Combines markup and backend logic.
• Page Structure: Divided into markup (UI) and code-behind (logic).
• Page Events: Manage page lifecycle and user interactions efficiently.
This structure simplifies the development of dynamic web applications in ASP.NET.
1. Properties in ASP.NET
Properties are members of a class that act as a bridge between private fields and the
external world. They allow controlled access to the fields of a class in ASP.NET code-
behind.
Syntax of Properties
private string _name; // Private field
63
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Key Points
• Encapsulation: Protects private fields while providing controlled access.
• Read-Only/Write-Only Properties: By defining only get or set.
• Auto-Implemented Properties: A shorthand for simple properties.
• public string Name { get; set; }
Example
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
}
64
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Examples in ASP.NET
Compiler Directives in Action
#define DEBUG
using System;
65
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
66
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
Key Features
• Dynamically add rows or cells via server-side code.
• Enhanced control over the table layout.
Example
// Adding a new row to the table in code-behind
TableRow row = new TableRow();
TableCell cell1 = new TableCell { Text = "New Data 1" };
TableCell cell2 = new TableCell { Text = "New Data 2" };
row.Cells.Add(cell1);
row.Cells.Add(cell2);
serverTable.Rows.Add(row);
67
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
NOTE:
1. Anchor Control: Creates hyperlinks, dynamically change href using server code.
2. Table Control: Displays data in rows and columns; rows can be added or modified
dynamically.
3. Form Control: Accepts user input and allows interaction between client and server.
These server controls make HTML elements more interactive and easier to manage within
ASP.NET applications.
1. Label
The Label control is used to display static or dynamic text on a web page.
Syntax
<asp:Label ID="lblMessage" runat="server" Text="Hello, ASP.NET!"></asp:Label>
Key Features
• Displays dynamic messages using Text property.
• Can be updated in code-behind.
Example
lblMessage.Text = "Welcome to ASP.NET!";
68
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
2. TextBox
The TextBox control is used for user input in text format.
Syntax
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
Key Features
• Supports single-line, multi-line, or password input (TextMode property).
• Use Text property to get or set user input.
Example
string name = txtName.Text;
3. Button
The Button control triggers an event when clicked.
Syntax
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
Key Features
• The OnClick event executes server-side code.
Example (Code-Behind)
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblMessage.Text = "Button clicked!";
}
4. Image
The Image control displays an image on the page.
Syntax
<asp:Image ID="imgLogo" runat="server" ImageUrl="logo.png" />
Key Features
• Dynamically change the image source using the ImageUrl property.
Example
imgLogo.ImageUrl = "newlogo.png";
5. LinkButton
The LinkButton control acts like a hyperlink but supports server-side events.
Syntax
69
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
6. CheckBox
The CheckBox control is used to select/unselect options.
Syntax
<asp:CheckBox ID="chkAgree" runat="server" Text="I agree to the terms" />
Key Features
• Check status can be read using the Checked property.
Example
if (chkAgree.Checked)
{
lblMessage.Text = "Thank you for agreeing!";
}
7. RadioButton
The RadioButton control is used for single-choice options within a group.
Syntax
<asp:RadioButton ID="rdoMale" runat="server" GroupName="Gender" Text="Male" />
<asp:RadioButton ID="rdoFemale" runat="server" GroupName="Gender" Text="Female" />
Key Features
• Group radio buttons using the GroupName property.
• Use the Checked property to determine the selected option.
Example
if (rdoMale.Checked)
{
lblMessage.Text = "You selected Male.";
}
70
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
8. HyperLink
The HyperLink control creates navigational links.
Syntax
<asp:HyperLink ID="lnkHome" runat="server" NavigateUrl="Home.aspx" Text="Go to
Home" />
Key Features
• Use the NavigateUrl property to specify the destination.
Example
lnkHome.NavigateUrl = "https://www.example.com";
These controls enhance user interactivity and simplify server-side handling of web forms in
ASP.NET.
UNIT – 4
CHOOSE THE BEST ANSWER:
1. What does ASP.NET stand for?
a) Active Service Pages .NET
b) Application Server Pages .NET
c) Active Server Pages .NET
d) Advanced Server Programming .NET
Answer: c) Active Server Pages .NET
2. Which property in the <%@ Page %> directive sets the programming language?
a) AutoEventWireup
71
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
b) Language
c) Inherits
d) CodeFile
Answer: b) Language
3. What is the main purpose of the runat="server" attribute?
a) To define the control as a client-side element
b) To make the control visible
c) To enable server-side processing
d) To handle JavaScript events
Answer: c) To enable server-side processing
4. Which ASP.NET page lifecycle event is raised before the page initializes?
a) Page_Init
b) Page_Load
c) Page_PreInit
d) Page_Unload
Answer: c) Page_PreInit
5. Which directive is used to conditionally compile code in ASP.NET?
a) #pragma
b) #region
c) #if
d) #define
Answer: c) #if
6. What is the default property to read user input in a TextBox control?
a) Input
b) Value
c) Text
d) Content
Answer: c) Text
7. Which control in ASP.NET is used to display static or dynamic text?
a) TextBox
b) Label
c) Button
d) HyperLink
Answer: b) Label
72
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
73
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
c) RadioButton
d) Label
Answer: c) RadioButton
14. Which property is used to redirect users using a HyperLink control?
a) Text
b) NavigateUrl
c) HRef
d) Destination
Answer: b) NavigateUrl
15. What is the purpose of the AutoEventWireup property in an ASP.NET page?
a) Automatically generates code
b) Wires events automatically to handlers
c) Enables client-side processing
d) Defines the control's ID
Answer: b) Wires events automatically to handlers
Five Mark Questions
1. What is the significance of the runat="server" attribute in ASP.NET HTML server
controls?
2. Explain the role of the Page_Load event in the ASP.NET page lifecycle.
3. Describe the difference between HTML controls and Web server controls in ASP.NET.
4. What is the use of the OnClick event in a Button control in ASP.NET? Provide an
example.
5. Explain the difference between the TextBox and Label controls in ASP.NET.
Ten Mark Questions
1. Explain the structure of an ASP.NET page, including the markup and code-behind
components. Provide an example.
2. Discuss the page lifecycle in ASP.NET, focusing on the key events such as Page_Init,
Page_Load, and Page_Unload.
3. Explain the use of compiler directives in ASP.NET with examples of #define, #region,
and #if.
4. Describe how HTML server controls like Anchor, Tables, and Forms are used in
ASP.NET. Provide examples for each.
5. Discuss the usage of Basic Web server controls in ASP.NET, such as Label, TextBox,
Button, and CheckBox. Explain their key properties and provide code examples.
74
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
UNIT – 5
Request and Response objects - Working with data – OLEDB connection class, Command
class Transaction class, data adaptor class, data set class.
Security: Authentication, IP Address, Secure by SSL & Client Certificates.
Response Object
The Response object is used to send information from the server to the client. It can
return content (HTML, JSON, etc.), set HTTP headers, and control redirection.
Features of the Response Object:
1. Sending Data to the Client:
o Response.Write(): Outputs content directly to the browser.
o Response.Redirect(): Redirects the user to another page.
75
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
NOTE:
• Request Object: Allows you to access and manipulate incoming request data from the
client.
• Response Object: Allows you to send data back to the client and control page
redirection.
76
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
77
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
command.Parameters.AddWithValue("@Password", "newPassword");
command.ExecuteNonQuery();
6. Deleting Data
Deleting data is done using DELETE statements.
Example:
string deleteQuery = "DELETE FROM Users WHERE Username = @Username";
SqlCommand command = new SqlCommand(deleteQuery, connection);
command.Parameters.AddWithValue("@Username", "UserToDelete");
command.ExecuteNonQuery();
NOTE:
• SqlConnection: Connects to the database.
• SqlCommand: Executes SQL queries.
• SqlDataReader: Reads the data from the database.
• GridView: Displays data in a tabular format on a web page.
In ASP.NET, when working with databases, the OLEDB classes can be used to connect and
interact with data sources like Microsoft Access, Excel, or other OLEDB-compatible
databases. Here’s a simple explanation of the key classes:
1. OLEDB Connection Class (OLEDBConnection)
Purpose: This class is used to establish a connection to a data source (like Access or
Excel) using OLEDB providers.
Example:
using System.Data.OLEDB;
78
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
try
{
command.CommandText = "UPDATE Users SET Password = 'newPassword' WHERE
Username = 'user1'";
command.ExecuteNonQuery();
transaction.Commit(); // Commit transaction if no error
}
catch
{
transaction.Rollback(); // Rollback if error occurs
}
4. Data Adapter Class (OLEDBDataAdapter)
Purpose: This class serves as a bridge between the OLEDBConnection and a DataSet. It
is used to fill the dataset with data and update the database.
Example:
OLEDBDataAdapter dataAdapter = new OLEDBDataAdapter("SELECT * FROM
Users", connection);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "Users");
79
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
NOTE:
OLEDBConnection: Establishes a connection to a database.
OLEDBCommand: Executes SQL queries or commands.
OLEDBTransaction: Manages transactions to group multiple operations.
OLEDBDataAdapter: Fills a DataSet with data from the database and updates the
database.
DataSet: Holds data in-memory, supporting multiple tables and relationships.
These classes are part of the System.Data.OLEDB namespace and help in managing and
manipulating data from various data sources using OLEDB technology.
80
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
2. IP Address
Purpose: Restricting access based on the user's IP address helps prevent unauthorized
users from accessing the application.
How to Implement: You can set rules to allow or deny access from specific IP addresses
in the web.config file or programmatically.
Example (Allow access from a specific IP):
<system.webServer>
<security>
<ipSecurity allowUnlisted="false">
<add ipAddress="192.168.1.100" allowed="true"/>
<add ipAddress="0.0.0.0" allowed="false"/>
</ipSecurity>
</security>
</system.webServer>
81
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
82
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
4. Client Certificates
Purpose: Client certificates are used for mutual authentication where both the client and
server authenticate each other.
How to Implement:
Require Client Certificates in IIS: Set up IIS to require a valid client certificate
for access.
Access Client Certificate in ASP.NET:
X509Certificate2 cert = Request.ClientCertificate;
if (cert != null)
{
// Use certificate details for further processing
string certSubject = cert.Subject;
string certIssuer = cert.Issuer;
}
NOTE:
1. Authentication: Verifies the identity of users through methods like forms
authentication or Windows authentication.
2. IP Address: Restricts access based on the user's IP address for additional security.
3. Secure by SSL: Uses encryption (SSL) to protect data in transit between the client
and server.
4. Client Certificates: Provides mutual authentication, where both the client and the
server authenticate each other using certificates.
UNIT – 5
CHOOSE THE BEST ANSWER:
1. What is the purpose of authentication in web security?
a) To verify the user's identity
b) To encrypt data
c) To limit access based on IP
d) To restrict website traffic
Answer: a) To verify the user's identity
83
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
84
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
a) <authentication>
b) <security>
c) <ipSecurity>
d) <serverSettings>
Answer: b) <security>
9. How can you force users to access your website over a secure connection (HTTPS)?
a) Enable cookies in the browser
b) Use SSL encryption
c) Redirect HTTP to HTTPS in web.config
d) Change the server port
Answer: c) Redirect HTTP to HTTPS in web.config
85
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
14. Which of the following is required to use client certificates for authentication?
a) SSL must be disabled
b) A valid client certificate must be installed in IIS
c) Cookies must be enabled
d) Usernames and passwords must be disabled
Answer: b) A valid client certificate must be installed in IIS
Five-Mark Questions:
1. Explain the purpose of authentication in web security and list two types of
authentication used in ASP.NET.
2. What is IP address filtering, and how can it be implemented in ASP.NET to restrict
unauthorized access?
3. Describe the role of SSL (Secure Sockets Layer) in securing data between client and
server.
86
AVS College of Arts & Science (Autonomous)
II – BBA WEB TECHNOLOGY THEORY AND PRACTICE
Ten-Mark Questions:
1. Discuss the different authentication methods in ASP.NET, highlighting the
differences between Forms Authentication and Windows Authentication. Provide
examples of each.
2. Explain how IP address filtering works in ASP.NET to enhance security. Provide an
example of how to configure IP address restrictions in the web.config file and
programmatically check the user's IP address.
3. Describe how SSL (Secure Sockets Layer) improves security in web applications.
Discuss how to configure SSL in an ASP.NET application and redirect traffic from
HTTP to HTTPS using the web.config file.
4. Explain the concept of mutual authentication using client certificates in ASP.NET.
How can you implement this feature in IIS and access the client certificate in the
application code?
5. Illustrate the use of authentication, IP address filtering, SSL, and client certificates in
securing an ASP.NET web application. Explain how each method contributes to the
overall security of the application.
87
AVS College of Arts & Science (Autonomous)