100% found this document useful (1 vote)
8K views113 pages

Web Technology - Questions - Answers-1

This document contains information about VBScript including: 1. Constants are defined using the Const keyword followed by the constant name and value. 2. Coding conventions provide guidelines for naming, commenting, formatting and indenting. 3. The Select Case statement is a control structure that allows one of many code blocks to execute based on the value of an expression.

Uploaded by

Karthik Ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
8K views113 pages

Web Technology - Questions - Answers-1

This document contains information about VBScript including: 1. Constants are defined using the Const keyword followed by the constant name and value. 2. Coding conventions provide guidelines for naming, commenting, formatting and indenting. 3. The Select Case statement is a control structure that allows one of many code blocks to execute based on the value of an expression.

Uploaded by

Karthik Ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 113

WEB TECHNOLOGY- Q&A

UNIT – I
2 MARKS
1. How constants are defined in VBScript?
Constants are defined in VBScript as follows
[Public | Private]ConstConstant_Name =Value

2. What are the coding conventions to be followed in VBScript?


Coding conventions can include the following:
 Naming conventions for objects, variables, and procedures.
 Commenting conventions.
 Text formatting and indenting guidelines.
3. Give the purpose of dialog box.(NOV-2012,14)
Dialog boxes can be used to raise an alert, or to get confirmation on any input or to have a kind of input
from the users.
4. How objects are defined in HTML?
The <object> tag defines an embedded object within an HTML document. Use this element to embed
multimedia (like audio, video, Java applets, ActiveX, PDF, and Flash) in your web pages. You can also use the
<object> tag to embed another webpage into your HTML document.
5. List the logical operators used in VBScript
Operator Description
And Performs a logical conjunction on two expressions (if both expressions
evaluate to True, result is True. If either expression evaluates to False,
result is False)
Or Performs a logical disjunction on two expressions (if either or both
expressions evaluate to True, result is True).
Not Performs logical negation on an expression.
Xor Performs a logical exclusion on two expressions (if one, and only one, of
the expressions evaluates to True, result is True. However, if either
expression is Null, result is also Null).

6. How variables are defined in VBScript (NOV-2013,APR-2013)


Variables are declared using “dim” keyword. Since there is only ONE fundamental data type, all the
declared variables are variant by default. Hence, a user need notmention the type of data during declaration.
Example 1: In this Example, IntValue can be used as a String, Integer or even arrays.
Dim var
Example 2: Two or more declarations are separated by comma(,)
Dim variable1,variable2
7. What is meant by Err object (APR-2013)
The Err object holds information about the last runtime error that occured. It is not necessary to create an
instance of this object; it is intrinsic to VBScript. Its default property is Number, which contains an integer
representing a VBScript error number or an ActiveX control Status Code (SCODE) number
8. Name any two control structures used in VBScript
 If Then Statement
 Select Case Statement
9. What are VBScript Datatypes
VBScript has only one data type called a Variant. It is a special kind of data type that can contain different
kinds of information, depending on how it's used. Because Variant is the only data type in VBScript, it's also the
data type returned by all functions in VBScript.
10. Write the syntax of Do-while loop in VBScript
The syntax of a Do..While loop in VBScript is:
Do While condition
[statement 1]
[statement 2]
...
[statement n]
[Exit Do]
[statement 1]
[statement 2]
...
[statement n]
Loop
11. Give the expansion of HTML (NOV.2012,NOV.2014)
HyperText Markup Language(HTML) is a set of standards used to tag the elements of a hypertext
document. It is the standard protocol for formatting and displaying documents on the World Wide Web
12. Define Loop (APR.2014)
A loop statement allows us to execute a statement or group of statements multiple times
13. What are the necessities of using HTML forms (JULY 2012)
HTML Forms are required, when we want to collect some data from the site visitor. For example, during
user registration you would like to collect information such as name, email address, credit card, etc.
14. State any four VB Script operators(APR.2012)
1. Arithmetic Operators
2. Comparison Operators
3. Logical Operators
4. Concatenation Operators
15. How is a date functions declared?(APR.2012)
Date functions help the developers to convert date from one format to another or to express the date
value in the format that suits a specific condition.
Syntax:-
variablename = Date_function_Name(Expression)

16. How will you create tables in HTML


 An HTML table is defined with the <table> tag.
 Each table row is defined with the <tr> tag. A table header is defined with the <th> tag. By default,
table headings are bold and centered. A table data/cell is defined with the <td> tag.
17. Name any four VBScript procedures.
Keywords Description
Null Used to indicate that a variable contains no
valid data.
IsEmpty Used to test if a variable is uninitialized.
True Used to indicate a Boolean condition that is
correct (True has a value of -1)
False Used to indicate a Boolean condition that is not
correct (False has a value of 0)
18. How to use Anchor tags
An anchor tag is an HTML tag. It is used to define the beginning and end of a hypertext link. It contains
visible words within a text that can be clicked and the URL of the link's target. Search engines use this HTML
tag in order to determine the subject matter of the linked target.
The syntax is:
<a href="http://www.beispiel.com">My sample page </a>

19. What is a form?


An HTML form is a section of a document containing normal content, markup, special elements
called controls (checkboxes, radio buttons, menus, etc.), and labels on those controls.

20. What are the variants in VBScript?


A Variant is a special kind of data type that can contain different kinds of information, depending on how
it's used. Because Variant is the only data type in VBScript, it's also the data type returned by all functions in
VBScript. A Variant can contain either numeric or string information.

21. How subroutines are defined in VBScript(JULY 2014)


We can declare subroutines using the Sub keyword and end them using the End Sub statement.
The structure of a subroutine is :

Sub Subroutine_Name(argument1,argument2,argumentn)
…..code within the subroutine
End Sub
22. Give the syntax of For….Next loop in VBScript(JULY.2014)
Syntax:
For counter=start To end [Step step]
[statements]
[Exit For]
[statements]
Next
23. What a class contains in VBScript (APR.2014)
 Class is a construct that is used to define a unique type.
 Classes can contain variables, properties, methods or events.
24. Name the properties in Error object handling
The Err has the following important properties.
 Err.Number - The code value of the runtime error. For example, Err.Number=1, 1 is the code value of
the “Division zero” error.
 Err.Description – The description string of the runtime error.
 Err.Source – The source string of the runtime error.

5 MARKS
1. Discuss the usage of dictionary object in VBScript (NOV.2012,APR. 2014,JULY 2014,APR. 2016)
The Dictionary object stores name/value pairs(referred to as the key and item respectively) in an array. The
key is a unique identifier for the corresponding item and cannot be used for any other item in the same
Dictionary object.
The following code creates a Dictionary object called “cars”, adds some key/item pairs, retrieves the item
value for the key ‘b’ using the Item property and then outputs the outputting string to the browser.
CODE:
<%
Dim cars
Set cars = CreateObject("Scripting.Dictionary")
cars.Add "a", "Alvis"
cars.Add "b", "Buick"
cars.Add "c", "Cadillac"
Response.Write "The value corresponding to the key 'b' is "
cars.Item("b")
%>

Output:
"The value corresponding to the key 'b' is Buick"
Explanation:
This code creates a Dictionary object called "cars", adds some key/item pairs, retrieves the item value for
the key 'b' using the Item property and then outputs the resulting string to the browser.
2. Explain on any one control statement used in VBScript
Select Case statement:-
We can also use the "Select Case" statement if you want to select one of many blocks of code to
execute:
Syntax:-
The syntax of a Switch Statement in VBScript is:
Select Case expression
Case expression list1
statement1
statement2
....
....
statement1n
Case expression list2
statement1
statement2
....
....
Case expression list n
statement1
statement2
....
....
Case Else
elsestatement1
elsestatement2
....
....
End Select

Example:-
d=weekday(date)
Select Case d
Case 1
response.write("Sleepy Sunday")
Case 2
response.write("Monday again!")
Case 3
response.write("Just Tuesday!")
Case 4
response.write("Wednesday!")
Case 5
response.write("Thursday...")
Case 6
response.write("Finally Friday!")
Case else
response.write("Super Saturday!!!!")
End Select

3. What is a procedure? How to use it in a VBScript (APR. 2012,2013,2015)


 Procedures are small logical components which breaks (splits) the program into a separate task.
 Procedures do their job by calling them from another procedure
 Procedures can take its arguments, perform a series of operations and changes the values of its
arguments
 The benefits of programming with procedures are
a. Debugging can be easily done
b. A procedure can act as a building block for another procedure in a program
 The general format of the VBScript procedures are as follows:

Procedure_typeProcedure_Name(argument_list)
the procedure heading
declaration statements
execution statements
End Procedure_type

A procedure can have two parts:


a. A declaration statement act as a reservation from the memory cells that are needed to hold data and
program output and what kind of information will be stored in each memory cell.
b. An execution statement is a statement that is translated into machine language and executed later.

4. Write a note on VBScript constants and variables(APR. 2015)


CONSTANTS:-
Constant is a named memory location used to hold a value that CANNOT be changed during the
script execution. If a user tries to change a Constant Value, the Script execution ends up with an error.
Constants are declared the same way the variables are declared.
Declaring Constants:-
Syntax:
[Public|Private]ConstConstant_Name=Value
The Constant can be of type Public or Private. The Use of Public or Private is Optional. The Public
constants are available for all the scripts and procedures while the Private Constants are available within
the procedure or class. One can assign any value such as number, String or Date to the declared
Constant.
Example 1:
In this example, the value of pi is 3.4 and it displays the area of the circle in a message box.
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
DimintRadius
intRadius=20
const pi=3.14
Area= pi*intRadius*intRadius
MsgboxArea
</script>
</body>
</html>

VARIABLES:-
VBScript variables are used to hold values or expressions. A variable can have a short name, like
x, or a more descriptive name, like carname.
Rules for VBScript variable names:
 Must begin with a letter
 Cannot contain a period (.)
 Cannot exceed 255 characters
In VBScript, all variables are of type variant, that can store different types of data.
Declaring (Creating) VBScript Variables:-

 Creating variables in VBScript is most often referred to as "declaring" variables.


 We can declare VBScript variables with the Dim, Public or the Private statement. Like this:
Dim x
Dim
carname

 Now we have created two variables. The name of the variables are "x" and "carname".
 we can also declare variables by using its name in a script. Like this:
carname="Volvo"

5. Write a short note on Math functions and Date functions


A.MATHEMATICAL FUNCTIONS:- (APR. 2013,APR. 2012)
Mathematical Functions help us to evaluate the mathematical and trigonometrical functions of a
given input number.
Syntax:-
variablename = Mathematical_function_Name(Expression)

Function Description
Int A Function, which returns the integer part of the given number
Log A Function, which returns the natural logarithm of the given
number. Negative numbers disallowed
Oct A Function, which returns the Octal value of the given
percentage
Hex A Function, which returns the Hexadecimal value of the given
number
Rnd A Function, which returns a random number between 0 and 1
Sgn A Function, which returns a number corresponding to the sign of
the specified number
Sqr A Function, which returns the square root of the given number.
Negative numbers disallowed
Abs A Function, which returns the absolute value of the given
number
Exp A Function, which returns the value of e raised to the specified
number
Sin A Function, which returns sine value of the given number
Cos A Function, which returns cosine value of the given number
Tan A Function, which returns tan value of the given number

B. DATE FUNCTIONS: (NOV.2012)


Date functions helps the developers to convert date from one format to another or to express the date
value in the format that suits a specific condition.
Syntax:-
variablename = Date_function_Name(Expression)

Function Description
Date A Function, which returns the current system date
CDate A Function, which converts a given input to Date
DateAdd A Function, which returns a date to which a specified time
interval has been added
DateDiff A Function, which returns the difference between two time
period
DatePart A Function, which returns a specified part of the given input
date value
DateSerial A Function, which returns a valid date for the given
year,month and date
FormatDateTime A Function, which formats the date based on the supplied
parameters
IsDate A Function, which returns a Boolean Value whether or not the
supplied parameter is a date
Day A Function, which returns an integer between 1 and 31 that
represents the day of the specified Date
Month A Function, which returns an integer between 1 and 12 that
represents the month of the specified Date
Year A Function, which returns an integer that represents the year
of the specified Date
MonthName A Function, which returns Name of the particular month for
the specified date
WeekDay A Function, which returns an integer(1 to 7) that represents the
day of the week for the specified day.
WeekDayName A Function, which returns the weekday name for the specified
day.

6. Describe about VBScript operators (NOV.2015,APR.2016)


In VBScript, operators are used to perform an operation. For example, an operator could be used to
assign a value to a variable. An operator could also be used to compare two values.
1. ARTITHMETIC OPERATORS:-
OPERATOR DESCRIPTION
+ Addition
- Subtraction
* Multiplication
/ Division
\ Integer Division (divides two numbers and returns an integer result)
Mod Modulus (remainder of a division)
^ Exponentiation (raises the number to the power of an exponent)

2. ASSIGNMENT OPERATOR:-
Operator Description

= Assign

3. COMPARISON OPERATORS:-
Operator Description
= Is equal to
<> Is not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to

4. LOGICAL OPERATORS:-
Operator Description
And Performs a logical conjunction on two expressions (if both expressions
evaluate to True, result is True. If either expression evaluates to False,
result is False)
Or Performs a logical disjunction on two expressions (if either or both
expressions evaluate to True, result is True).
Not Performs logical negation on an expression.
Xor Performs a logical exclusion on two expressions (if one, and only one,
of the expressions evaluates to True, result is True. However, if either
expression is Null, result is also Null).

5. CONCATENATION OPERATORS
Operator Description
& Concatenate (join two strings together)
+ Adds two numbers together

7. How to define a VBScript Procedure? Explain with an example


The general format of the VBScript procedures are as follows:
Procedure_typeProcedure_Name(argument_list)
the procedure heading
declaration statements
execution statements
End Procedure_type

A procedure can have two parts:


a. A declaration statement act as a reservation from the memory cells that are needed to hold data and
program output and what kind of information will be stored in each memory cell.
b. An execution statement is a statement that is translated into machine language and executed later.
Example:-
<html>
<body>
<script language="vbscript" type="text/vbscript">
Function sayHello()
msgbox("Hello there")
End Function
</script>
</body>
</html>

8. How to add VBScript code to an HTML page?(NOV.2012,14,APR.2012)


 To add VBScript code to an HTML page, enclose the script within a pair of <SCRIPT> tags, using
either the TYPE attribute or the LANGUAGE attribute to specify the scripting language.
 we can place VBScript code blocks anywhere on an HTML page. In fact, it is a good practice to put all
general-purpose scripting code (that is, script that is not tied to a particular form control) in the HEAD
section.
 This ensures that script will already have been read and decoded before it is called from the body of the
HTML page.
Syntax:-
<html>
<head>
<script type="text/vbscript">
// VBScript code here
</script>
</head>
</html>

We can also place <script> tag within the <body> …</body> tags as follows.
<html>
<head>
<title>Untitled page</title>
</head>
<body>
<script type="text/vbscript">
// VBScript code here
</script>
</html>

Example:-
<html>
<body>
<script type="text/vbscript">
document.write("Hello World!")
</script>
</body>
</html>

OUTPUT:- Hello World!


9. Discuss the usage of date functions in VBScript
 Date functions helps the developers to convert date from one format to another or to express the date
value in the format that suits a specific condition
 Date function is used to display current system date while working on the script and is the most basic
and widely used function which is used while working with the Dates.
 There are various Date format functions available for converting the Date into different formats.
Syntax:-
variablename = Date_function_Name(Expression)
Refer Q.NO-5(B. DATE FUNCTIONS)(in 5 Marks)

10. Write about VBScript basics and datatypes(NOV. 2014)


VBScript:-
 Microsoft VBScript (Visual Basic Script) is a general-purpose, lightweight and active scripting
language developed by Microsoft that is modelled on Visual Basic.
 VBScript is an interpreted script language from Microsoft that is a subset of its Visual
Basic programming language designed for interpretation by Web browsers
 VBScript is a propriety client side scripting language by Microsoft, supported by Internet Explorer.
 It is widely used in enterprises.
 Nowadays, VBScript is the primary scripting language for Quick Test Professional (QTP), which is
a test automation tool.
Datatypes:- (JULY 2012)
VBScript includes a default data type called the "Variant", which may contain different information
depending on the context in which it is used. To define a variable, simply assign a value with the syntax
specific to the type that you want to use As follows:
 a string is enclosed in quotation marks
 a float number consists of digits and a point
 an integer consists of numbers only
The Variant subtypes
Sub-type Description

Empty It is the default value of a variable, that is to say the value of the variable before
initialiazation

Null The the value of a variable when its content is incorrect

Boolean Contain the folllwing values True or False

Byte Contains an integer between 0 and 255

Currency Contains a currency value ranging from -922 337 203 685 477.5808 to 922 337
203 685 477.5807
This is a sub-type suitable for large financial values

Long Contains a long integer whose value is between -2 147 483 648 to 2 147 483 647

Single Contains a float value ranging between -3,402823E38 and -1,401298E-45 for
negative values and between 1,401298E-45 and 3,402823E38 for the positive
values
Double Contains a float value, ranging between 1,79769313486232E308 and -
4,94065645841247E-324 for negative values and between 4,94065645841247E-
324 to 1,79769313486232E308 for positive values

Date / Time contains a date between 1th January 100 and 31 December 9999.

String Contains a string that can contain several billion characters

Object Can contain any object

Error Contains an error identifier

11. Write a note on VBScript variables and Operators (NOV-2015)


VARIABLES:-
VBScript variables are used to hold values or expressions.A variable can have a short name, like x,
or a more descriptive name, like carname.
Rules for VBScript variable names:
 Must begin with a letter
 Cannot contain a period (.)
 Cannot exceed 255 characters
In VBScript, all variables are of type variant, that can store different types of data.
Declaring (Creating) VBScript Variables:-

Creating variables in VBScript is most often referred to as "declaring" variables.we can declare
VBScript variables with the Dim, Public or the Private statement. Like this:
Dim x
Dim
carname

Now we have created two variables. The name of the variables are "x" and "carname".
we can also declare variables by using its name in a script. Like this:
carname="Volvo"
OPERATORS:- (JULY 2012) Refer Q.NO-6 (in 5-Marks)
12. Explain the execution of for… Next loop in VBScript
For...Next Loop:-
We can use the For...Next statement to run a block of code a specified number of times.
The For statement specifies the counter variable (i), and its start and end values. The Next statement
increases the counter variable (i) by one.
Syntax:-
For var_name = Start_value To End_value
// body of the loop
Next
Example:-
The following example causes a procedure called MyProc to execute 50 times. The For statement
specifies the counter variable x and its start and end values. The Next statement increments the
counter variable by 1.
Sub DoMyProc50Times()
Dim x
For x = 1To50
MyProc
Next
End Sub

13. What are the built in functions available in VBScript? Discuss them with examples.
A built in function that is built into an application and can be accessed by end-users
VBScript Built in functions are as follows:
1. Mathematical functions
2. Date and Time functions
3. String functions
1. MATHEMATICAL FUNCTIONS:-
Mathematical Functions help us to evaluate the mathematical and trigonometrical functions of a given
input number.
Syntax:-
variablename = Mathematical_function_Name(Expression)

Function Description
Int A Function, which returns the integer part of the given number
Fix A Function, which returns the integer part of the given number
Log A Function, which returns the natural logarithm of the given number. Negative numbers
disallowed
Oct A Function, which returns the Octal value of the given percentage
Hex A Function, which returns the Hexadecimal value of the given number
Rnd A Function, which returns a random number between 0 and 1
Sgn A Function, which returns a number corresponding to the sign of the specified number

Sqr A Function, which returns the square root of the given number. Negative numbers
disallowed
Abs A Function, which returns the absolute value of the given number
Exp A Function, which returns the value of e raised to the specified number
Sin A Function, which returns sine value of the given number
Cos A Function, which returns cosine value of the given number
Tan A Function, which returns tan value of the given number
Examples:
Abs Function
Returns the absolute value of a number.
Dim num OUTPUT: num=50.33
num=abs(-50.33)
msgbox num
Sin
Returns the sine value of a number
Dim num OUTPUT: num=0.5
num=sin(30)
msgbox num

2.DATE FUNCTIONS:-
Date functions helps the developers to convert date from one format to another or to express the date
value in the format that suits a specific condition.
Syntax:-
variablename = Date_function_Name(Expression)

Function Description
Date A Function, which returns the current system date
CDate A Function, which converts a given input to Date
DateAdd A Function, which returns a date to which a specified time interval has been
added
DateDiff A Function, which returns the difference between two time period
DatePart A Function, which returns a specified part of the given input date value
DateSerial A Function, which returns a valid date for the given year,month and date
FormatDateTime A Function, which formats the date based on the supplied parameters
IsDate A Function, which returns a Boolean Value whether or not the supplied
parameter is a date
Day A Function, which returns an integer between 1 and 31 that represents the day
of the specified Date
Month A Function, which returns an integer between 1 and 12 that represents the
month of the specified Date
Year A Function, which returns an integer that represents the year of the specified
Date
MonthName A Function, which returns Name of the particular month for the specified date
WeekDay A Function, which returns an integer(1 to 7) that represents the day of the
week for the specified day.
WeekDayName A Function, which returns the weekday name for the specified day.

Examples:
 Date Function- It returns current system Date
Dim myDate OUTPUT: 17-03-2018
myDate=Date
msgbox myDate
 IsDate- It checks weather the given value is Date type or not
Examples:
1. Dim myDate,x OUTPUT: False
myDate=100
x=IsDate(myDate)
msgbox x

2. myDate="India" OUTPUT: False


x=IsDate(myDate)
msgbox x

3.myDate=#10/05/2010# OUTPUT: True


x=IsDate(myDate)
msgbox x
 DateDiff Function- It provides difference between two dates, based on interval day/month) or
Returns the number of intervals between two dates.
Examples:
Dim Date1, Date2, x

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("yyyy", Date1, Date2)
Msgbox x 'Differnce in Years

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("q", Date1, Date2)
Msgbox x 'Differnce in Quarters

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("m", Date1, Date2)
Msgbox x 'Differnce in Months

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("w", Date1, Date2)
Msgbox x 'Differnce in weeks

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("d", Date1, Date2)
Msgbox x 'Differnce in days

Likewise, Hours, Minutes and Seconds can be calculated.

2. STRING FUNCTIONS:-
String functions helps the developers to work with the strings effectively. Below are string methods
supported in VBScript
Syntax:-
variablename = String_function_Name(Expression)

Function Description

InStr Returns the first occurrence of the specified substring. Search happens from left
to right.
InstrRev Returns the first occurrence of the specified substring. Search happens from
Right to Left.
Lcase Returns the lower case of the specified string.
Ucase Returns the Upper case of the specified string.
Left Returns a specific number of characters from the left side of the string.

Right Returns a specific number of characters from the Right side of the string.

Mid Returns a specific number of characters from a string based on the specified
parameters.
Ltrim Returns a string after removing the spaces on the left side of the specified string.

Rtrim Returns a string after removing the spaces on the right side of the specified
string.
Trim Returns a string value after removing both leading and trailing blank spaces.

Len Returns the length of the given string.


Replace Returns a string after replacing a string with another string.
Space Fills a string with the specified number of spaces.
StrComp Returns an integer value after comparing the two specified strings.

String Returns a String with a specified character the specified number of times.

StrReverse Returns a String after reversing the sequece of the characters of the given string.

Len Function- It finds length of the String


Example:
Dim val,x OUTPUT: 9
val="Hyderabad"
x=Len(val)
msgbox x
Left Function- Returns a specified number of characters of a given string from left side
Syntax:
variable=Left(string,Lengh) OUTPUT: Hyd
Example:
Dim val,x
val="Hyderabad"
x=Left(val,3)
msgbox x
Right Function - Returns a specified number of charectors of a given string from Right side
Example:
Dim val,x OUTPUT: bad
val="Hyderabad"
x=Right(val,3)
msgbox x
Mid function- Returns a specified number of characters of a given string
Example:
Dim val,x OUTPUT: rab
val="Hyderabad"
x=Mid(Val,5,3)
msgbox x
StrReverse-Retuns reverse value of a string
Example:
Dim val,x OUTPUT: dabaredyH
val="Hyderabad"
x=StrReverse(val)
msgbox x
3. OTHER FUNCTIONS:-
FUNCTION DESCRIPTION
CreateObject Creates an object of a specified type
Eval Evaluates an expression and returns the result
RGB Returns a number that represents the RGB color value

Round Rounds a number


Round -Returns a number rounded to a specified number of decimal places.
Example:
Dim num OUTPUT: num=173
num=172.499
num=Round(num),msgbox num
RGB -The RGB function returns a number that represents an RGB color value.

Syntax: RGB(red, green, blue)

Parameter Description
red Required. A number from 0 to 255, inclusive, representing the red component of the
color
green Required. A number from 0 to 255, inclusive, representing the green component of the
color
blue Required. A number from 0 to 255, inclusive, representing the blue component of the
color

Example:

<%response.write(rgb(255,0,0))%>

The output of the code above will be:255 ‘red

Eval Function-Evaluates an expression and returns the result.

14. Explain the execution of While…Wend loop in VBScript(JULY 2014)


In a While..Wend loop, if the condition is True, all statements are executed until Wend keyword is
encountered.
If the condition is false, the loop is exited and the control jumps to very next statement after Wend keyword.

Syntax
The syntax of a While..Wend loop in VBScript is:
While condition(s)
[statements 1]
[statements 2]
...
[statements n]
Wend
15. Explain VBScript in detail (JULY 2012)
VBScript:-
 Microsoft VBScript (Visual Basic Script) is a general-purpose, lightweight and active scripting
language developed by Microsoft that is modelled on Visual Basic.
 VBScript is an interpreted script language from Microsoft that is a subset of its Visual
Basic programming language designed for interpretation by Web browsers
 VBScript is a propriety client side scripting language by Microsoft, supported by Internet Explorer.
 It is widely used in enterprises.
 Nowadays, VBScript is the primary scripting language for Quick Test Professional (QTP), which is
a test automation tool.
Adding VBScript code into HTML:-
 To add VBScript code to an HTML page, enclose the script within a pair of <SCRIPT> tags, using
either the TYPE attribute or the LANGUAGE attribute to specify the scripting language.
 You can place VBScript code blocks anywhere on an HTML page. In fact, it is a good practice to
put all general-purpose scripting code (that is, script that is not tied to a particular form control) in
the HEAD section.
 This ensures that script will already have been read and decoded before it is called from the body of
the HTML page.
Syntax:-
<html>
<head>
<script type="text/vbscript">
// VBScript code here
</script>
</head>
</html>

We can also place <script> tag within the <body> …</body> tags as follows.
<html>
<head>
<title>Untitled page</title>
</head>
<body>
<script type="text/vbscript">
// VBScript code here
</script></html>
Example:-
<html>
<body>
<script type="text/vbscript">
document.write("Hello World.!")
</script>
</body>
</html>

OUTPUT:-
Hello World.!
16. What are the String functions in VBScript (JULY 2012,APR.2014)
Refer Q.NO-13(in 5-Marks)

10 MARKS
1. Discuss the string functions in VBScript with examples (NOV. 2014)
Refer Q.NO-13(in 5-Marks)
2. Mention the salient features of VB Script (APR. 2013)
Features of VBScript:-
 VBScript is a lightweight scripting language, which has a lightning fast interpreter.
 VBScript, for the most part, is case insensitive. It has a very simple syntax, easy to learn and to
implement.
 Unlike C++ or Java, VBScript is an object-based scripting language and NOT an Object-Oriented
Programming language.
 It uses Component Object Model (COM) in order to access the elements of the environment in
which it is executing.
 Successful execution of VBScript can happen only if it is executed in Host Environment such as
Internet Explorer (IE), Internet Information Services (IIS) and Windows Scripting Host (WSH)
 VBScript is also used for Network Administration, System Administration and for UFT Test
Automation.
 If we already know Visual Basic (VB) or Visual Basic for Applications (VBA), VBScript will be
very familiar.
 The basic concepts of VBScript are common to most programming languages.
 VBScript talks to host applications using Windows Script. With Windows Script, browsers and other
host applications do not require special integration code for each scripting component.

3. Describe on VBScript coding conventions and Err object(NOV.2012,APR. 2012,APR.2015)


CODING CONVENTIONS:-
Coding conventions are suggestions are designed to help us write code using VB Script.
Coding conventions can include the following:
• Naming conventions for objects, variables, and procedures
• Commenting conventions
• Text formatting and indenting guidelines
The main reason for using a consistent set of coding conventions is to standardize the structure and
coding style of a script or set of scripts so that we and others can easily read and understand the code.
1. Variable Naming Conventions:_
To enhance readability and consistency, we have to use the following prefixes with descriptive names
for variables in our VBScript code.
SUBTYPE PREFIX EXAMPLE
Boolean Bln blnFound
Byte Byt bytRasterData
Date(Time) Dtm dtmStart
Double Dbl dblTolerance
Error Err errOrderNum
Integer Int IntQuantity
Long Lng lngDistance
Object Obj objCurrent
Single Sng sngAverage
String Str strFirstName

2. Object Naming Conventions:


The following table lists recommended conventions for objects you may encounter while programming
VBScript.
OBJECT TYPE PREFIX EXAMPLE
3D Panel Pnl pnlGroup
Animated ani aniMailBox
Check box chk chkReadOnly
Combo box Cbo cboEnglish
Command button cmd cmdExit
Common dialog dlg dlgFileOpen
Frame Fra fraLanguage
Image Img imgIcon
Label Lbl lblHelpMessage
Line Lin linVertical
List Box Lst lstPolicyCodes
Spin Spn spnPages
Text Box Txt txtLastName
Slider Sld sldScale

3. Code Commenting Conventions


All procedures should begin with a brief comment describing what they do. This description should
not describe the implementation details (how it does it) because these often change over time, resulting in
unnecessary comment maintenance work, or worse, erroneous comments. The code itself and any necessary
inline comments describe the implementation.
Arguments passed to a procedure should be described when their purpose is not obvious and when
the procedure expects the arguments to be in a specific range. Return values for functions and variables that
are changed by a procedure, especially through reference arguments, should also be described at the
beginning of each procedure.
Procedure header comments should include the following section headings. For examples, see the
"Formatting Your Code" section that follows.
SECTION HEADING COMMENT CONTENTS
Purpose What the procedure does (not how).
Assumptions List of any external variable, control, or other element whose state affects this
procedure.
Effects List of the procedure's effect on each external variable, control, or other
element.
Inputs Explanation of each argument that is not obvious. Each argument should be
on a separate line with inline comments.
Return Values Explanation of the value returned.

ERR OBJECT:-
The Err object holds information about the last runtime error that occured. It is not necessary to create
an instance of this object; it is intrinsic to VBScript. Its default property is Number, which contains an integer
representing a VBScript error number or an ActiveX control Status Code (SCODE) number.
This value is automatically generated when an error occurs and is reset to zero (no error) after an On
Error Resume Next statement or after using the Clear method.
Examples:
<%
dim numerr, abouterr
On Error Resume Next
Err.Raise 6
numerr = Err.number
abouterr = Err.description
If numerr<> 0 Then
Response.Write "An Error has occured! Error number " numerr " of the type '" abouterr "'."
End If
%>
Output:
"An Error has occured! Error number 6 of the type 'Overflow'."
Explanation:
This code checks the value of the Number property and, if it contains a value other than zero, displays
the details in the browser.
PROPERTIES:
1. Description
Syntax: object. Description [ =string]
This property returns or sets a string containing a brief textual description of an error.
2. HelpContext
Syntax: object.HelpContext[ =contextID]
This property is used to set or return a context ID for a Help topic specified with the HelpFile property.
3. HelpFile
Syntax: object. HelpFile[ =contextID]
This property is used to get or define the path to a Help file.
4. Number
Syntax: object.Number[ =errnumber]
This property is used to retrieve or set the value that relates to a specific runtime error.
5. Source
Syntax: object. Source [ =string]
This property lets us determine the object or application that caused an error, and returns a string that
contains its Class name or programmatic ID.
METHODS:-
1. Clear
Syntax: object.Clear
This method is used to clear teh settings of the Error object.
2. Raise
Syntax: object.Raise(number[, source, description, helpfile, helpcontext])
This method is used to generate a VBScript runtime error.

4. How to use dictionary object in VBScript? Explain (NOV. 2015)


DICTIONARY OBJECTS:-
A Dictionary object can be compared to a PERL associative array. Any Values can be stored in the array
and each item is associated with a unique key. The key is used to retrieve an individual element and it is usually
an integer or a string, but can be anything except an array.
Syntax:-
VBScript classes are enclosed within Class .... End Class.
Dimvariablename
Setvariablename=CreateObject("Scripting.Dictionary")
variablename.Add(key, item)

Example
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","Clear"
</script>
</body>
</html>
1. EXISTS METHOD:-
Exist Method helps the user to check whether or not the Key Value pair exists.
object.Exists(key)
where,
Object - a Mandatory Parameter. This represents the name of the Dictionary Object.
Key - a Mandatory Parameter. This represents the value of the Dictionary Object.
Example
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dim d,msg'Create some variables.
Set d =CreateObject("Scripting.Dictionary")
d.Add"a","Apple"'Add some keys and items.
d.Add"b","BlueTooth"
d.Add"c","C++"
Ifd.Exists("c")Then
msgbox"Specified key exists."
Else
msgbox"Specified key doesn't exist."
EndIf
</script>
</body>
</html>
Save the file as .HTML, and upon executing the above script in IE, it displays the following message in
a message box.
OUTPUT:-
Specified key exists.
2. ITEMS METHOD:-
Items Method helps us to get the values stored in the key value pair of the data dictionary object.
object.Items()
where,
Object- a Mandatory Parameter. This represents the name of the Dictionary Object.
Example:-
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","C++"
a=obj_datadict.items
msgboxa(0)
msgboxa(2)
</script>
</body>
</html>
Save the file as .HTML, and upon executing the above script in IE, it displays the following message in
a message box.
OUTPUT:-
Apple
C++
3. KEYS METHOD:-
object.Keys()
where,
Object- a Mandatory Parameter. This represents the name of the Dictionary Object.
Example:-
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","C++"
a=obj_datadict.Keys
msgboxa(0)
msgboxa(2)
</script>
</body>
</html>
Save the file as .HTML, and upon executing the above script in IE, it displays the following message in a
message box.
OUTPUT:-
a
c
4. REMOVE METHOD:-
object.Remove(key)
where,
Object- a Mandatory Parameter. This represents the name of the Dictionary Object.
Key - a Mandatory Parameter. This represents the key value pair that needs to be removed from the Dictionary
Object.
Example:-
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","C++"
a=obj_datadict.Keys

msgboxa(0)
msgboxa(2)
obj_datadict.remove("b")'The key value pair of "b" is removed'
</script>
</body>
</html>
Save the file as .HTML, and upon executing the above script in IE, it displays the following message in
a message box.
OUTPUT:-
a
c
5. REMOVE ALL METHOD:-
object.RemoveAll()
where,
Object - a Mandatory Parameter. This represents the name of the Dictionary Object.
Example:-
<html>
<body>
<scriptlanguage="vbscript"type="text/vbscript">
Dimobj_datadict'Create a variable.
Setobj_datadict=CreateObject("Scripting.Dictionary")
obj_datadict.Add"a","Apple"'Add some keys and items.
obj_datadict.Add"b","Bluetooth"
obj_datadict.Add"c","C++"
a=obj_datadict.Keys
msgboxa(0)
msgboxa(2)
obj_datadict.removeall

</script>
</body>
</html>
5. Explain how anchor tags are used in HTML (NOV.2014)
An anchor tag is an HTML tag. It is used to define the beginning and end of a hypertext link. It contains
visible words within a text that can be clicked and the URL of the link's target. Search engines use this HTML
tag in order to determine the subject matter of the linked target.
Building a Hyperlink with an Anchor Tag:-
<a href="http://www.beispiel.com">My sample page </a>

An Anchor tag is defined with '<a>' and consists of three parts:


1. the href attribute,
2. the name attribute and
3. the target attribute.
1.The href attribute:-
To create a hyperlink, the destination (address) of the document must be known. A hyperlink can link to
pages on your own domain, to other websites, or to a file (such as a PDF document).
If you want to link to the Google homepage, the code looks as follows from:
<a href="http://www.google.com">Google Home</a>

Href is short for hypertext reference. This attribute defines the target address of the document, which is
to be linked to (http://www.google.com). The “=” sign is the connection of the attribute with the attribute value,
whereby “href” is the attribute and “ http://www.google.com ” is the attribute value. There is an apostrophe
before and after the attribute value. The defined phrase “Google Home” is called anchor text or link text. This
part is clickable in the text. An anchor text is ideally informative and relevant to the landing page.
2. Name attribute:-
The name attribute of the anchor tag can be used to enable users to “jump” to a specific point on a page
(jump marker, anchor). This is especially useful with large pages or subdivisions.
The HTML code looks like this:
<a name="to top"></a> or
<a name="Content">Content</a>

In the first code sample, you link from the bottom of a page back to the beginning. So users can quickly
get to the top of that page without having to scroll for a long time. In the second example, users can get direct
access to the page, for example, by linking to a subdivision point. By clicking, users are guided via name
attribute directly to the subject.
<a href="#Content">Content</a>

By simply setting a hash tag (#) at the anchor name the browser can identify a jump within the page.
3. Target attribute:-
The target attribute specifies how the destination page or the target document should be opened.
“target=” _ blank “ is used for opening of the target page in a new window. This is the usual option when using
target attributes for linking to other pages.
<a href="http://www.mypage.com" target="_blank">Linktext</a>

6. Write a detailed note on functions in VBScript


 A Function is a series of statements, enclosed by the Function and End Function statements.
 It can perform actions and can return a value.
 It can take arguments that are passed to it by a calling procedure.
 Without arguments, must include an empty set of parentheses ().
 It returns a value by assigning a value to its name.

Function myfunction()
some statements
myfunction=some value
End Function

(Or)

Function myfunction(argument1,argument2)
some statements
myfunction=some value
End Function
Calling a Function:-

This simple function procedures is called to calculate the sum of two arguments:
Example:-
Function myfunction(a,b)
myfunction=a+b
End Function
response.write(myfunction(5,9))
The function "myfunction" will return the sum of argument "a" and argument "b". In this case 14.

When we call a procedure you can use the Call statement, like this:
Call MyProc(argument)
Or, you can omit the Call statement, like this: MyProc argument
VBScript Built in functions are as follows:
 Mathematical functions
 Date and Time functions
 String functions
Refer Q.NO-13(in 5-Marks)

UNIT-II

2 MARKS
1. Write down the JavaScript comments.(APR.2016,NOV.2014)
 Single line comments start with //.
 Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
 Multi-line comments start with /* and end with */.
 Any text between /* and */ will be ignored by JavaScript.
2. How to use conditional expression in JavaScript?(APR.2006)
The conditional (ternary) operator is the only JavaScript operator that takes three operands.
This operator is frequently used as a shortcut for the if statement.
Syntax:-
variablename = (condition) ? value1:value2

Example:-
var voteable = (age < 18) ? "Too young":"Old enough";
3. Explain the break statement in Java Script.(APR.2006)
Break statement will break the loop and continue executing the code that follows after the loop.
Example:-
for(i=0;i<=5;i++)
{
if(i==3)
{
break
}document.write(+i)
}
4. How to define and use function in Java Script?(APR.2008)
Defining function
Function function_name(parameter1,parameter2,….)

// block of JavaScript code

5. List the arithmetic operators used in JavaScript.(Apr .2011,Apr.2013)


Operator Description

+ Addition

- Subtraction or Unary negation

* Multiplication

/ Division

% Modulus

++ Return the value then Increment

-- Return the value then Decrement

6. Define array.(APR .2011, APR.2016, NOV. 2013)

Arrays are JavaScript objects that are capable of storing a sequence of values. These values are
stored in indexed locations within the array.

7. How to create arrays in JavaScript?(APR.2011)


An array must be declared before it is used. An array can be declared using any one of the
following technique.
arrayName = new Array(Array length)
arrayName = new Array( )
8. List the 2 types of expressions supported in JavaScript. (NOV.2011,NOV.2014)
JavaScript has the following kinds of expressions:
Arithmetic: evaluates to a number, for example.
String: evaluates to a character string, for example "Fred" or "234"
Logical: evaluates to true or false.
9. How an arithmetic expression is evaluated in JavaScript. (APR.2013)
Using the eval built in function expression is calculated. Eg., eval(“5+5*2”).
10. Define Function. (NOV 2011)
A function is a reusable code-block that will be executed by an event, or when the function is
called. To keep the browser from executing a script when the page loads, we can put our script into a
function .A function contains code that will be executed by an event or by a call to that function.
11. How will you call function in JavaScript? (APR.2012, NOV.2014)
Function Declaration
Function printName(user){
document.write(“<HR>Your Name is<B><I>”);
document.write(user);
document.write(“</B><I>”);
}
Function call
printName(“Ram”);
A Variable Passed
Var user=”John”;
printName(user);
12. What do you mean by this keyword? (APR.2012)
In JavaScript, the thing called this, is the object that "owns" the JavaScript code. The value of
this, when used in a function, is the object that "owns" the function. The value of this, when used in an
object, is the object itself. The this keyword in an object constructor does not have a value.

13. How browsers recognize JavaScript code? (APR.2012)


Browser recognize the Javascript code by <SCRIPT>…</SCRIPT> tag. The <SCRIPT> tag
marks the beginning of a snippet of scripting code.The paired </SCRIPT> marks the end of the snippet
of scripting code.
<SCRIPT Language=”JavaScript”>
//JavaScript code snippet written here
</SCRIPT>
14. Which tag is must in the external JavaScript file? (NOV.2012)
The src attribute specifies the URL of an external script file.If you want to run the same
JavaScript on several pages in a web site, you should create an external JavaScript file, instead of
writing the same script over and over again. Save the script file with a .js extension, and then refer to it
using the src attribute in the <script> tag.
Example : <script src="myscripts.js"></script>
15. How does a while loop start? State with example. (NOV.2012)
The while loop is used when we want the loop to execute and continue executing while the specified
condition is true.
Example: The example below defines a loop that starts with i=0.The loop will continue to run as long as
I is less than, or equal to 5. I will increase by 1 each time the loop runs.
16. Define Constructor.(Apr.2013,Apr.2016)
A constructor is useful when we want to create multiple similar objects with the same properties and
methods. It’s a convention to capitalize the name of constructors to distinguish them from regular
functions.

17. Mention the Purpose of Dialog Box. (APR.2014,NOV .2013,NOV.2014)


Dialog box is used to get the user input or display small amount of text to the user.
18. Write a note on JavaScript.
 Java script is an object-oriented language that allows creation of interactive web pages.
 Java script is a platform-independent, event-driven, interpreted client – side scripting and
programming language developed by Netscape Communicator.
19. Define outputting text.
The document object has a method for placing text in a browser. This method is called write().
Methods are called by combining the object name with the method name:
Syn: Object-name.Method-Nameeg.document.write
20. What are assignment operators in JavaScript?
Operator Description

= Sets the variable

+= Increments the variable

-= Decrements the variable

*= Multiplies the Variable

/= Divides the variable

%= Takes the modulus of the variable

21. Explain the operator precedence.


Operator precedence determines the order in which operators are evaluated.The
multiplication operator (" * ") has higher precedence than the addition operator (" + ") and thus will be
evaluated first.
22. How to get user input in JavaScript?
Using prompt dialog box or by using form elements we can get the input from the user.

ENTER A NUMBER
prompt X
Enter the number OK CANCEL
5 Ok

23. Write the data types of JavaScript.


Datatypes

Primitive complex

Number Array
Boolean Objects
String
Null
24. How an array is defined in JavaScript?
Arrayname=new Array(array length)
Eg.Flower=new Array(5)
25. List any three commands in JavaScript with example.
Var,break,continue.
26. Define: NULL value.
The null value is a unique value representing no value or no object. It implies no object, or null string ,
no valid Boolean value, no number and no array object.
27. Explain the comparison operator in Java Script.

Comparison operators are used to compare two values. The comparison operators supported by
JavaScript are:

OPERATOR DESCRIPTION

== Equal

=== Strictly Equal

!= Not Equal

!== Strictly Not Equal

< Less than

<= Less than or equal to

> Greater than

>= Greater than or equal to

28. List out various types of dialog boxes in JavaScript.


Alert box, Confirm box and Prompt box.
29. Write a note on scope of variables in JavaScript.
Local variable: A variable declared with in a function.
Global variable: A variable declared outside the function and it is available to all statements within the
javascript.
30. Define Loop.(NOV.2013, APR.2014, NOV.2014)
Repeats a block of code for a specified number of times or until the condition is met.
2 types of loop

for while
31. Name any two user defined functions in JavaScript.(NOV.2013)
User defined function first needs to be declared and coded and that can be invoked by calling it using the
name given when it was declared. Eg.functionclass, function mark.
32. How to create variables in JavaScript?
Variables can be created that can hold any type of data. Variables can be declared using varcommand.
Syntax: var<variable name>=value;

Eg., Var car;


Var car= “ford”;
Var model=2005;
5 MARKS
1. Write about JavaScript syntax and looping.(APR.2015)

JAVASCRIPT SYNTAX:-

 JavaScript syntax is embedded into an HTML file.


 A browser reads HTML files and interprets HTML tags.
 Since all JavaScripts need to be included as an integral part of an HTML document when required,
the browser needs to be informed that specific sections of HTML code is JavaScript.
 The browser will then use its built in JavaScript engine to interpret this code.

SYNTAX:-

<SCRIPT LANGUAGE=”JavaScript”>

// JavaScript code snippet here

</SCRIPT>

 The browser is given this information using the HTML tags <SCRIPT>….</SCRIPT>.
 The <SCRIPT> tag marks the beginning of a snippet of scripting code.
 The paired </SCRIPT> tag marks the end of a snippet of scripting code.

Like most other HTML tags, the <SCRIPT> tag takes in an optional attribute, as listed below.

Attributes Description

Language Indicates the scripting language used for


writing the snippet of scripting code.

LOOPING:-

 Looping refers to the ability of a block of code to repeat itself.


 This repetition can be for a predefined number of times or it can go until certain conditions are met.
 For instance, a block of code needs to be repeated 7 times.

For this purpose, JavaScript offers 2 types of loop structures

1. for Loops – These loops iterate a specific number of times as specified


2. while Loops – These are conditional loops, which continue until a condition is met.

For Loop:- Syntax:-

for(expression1;condition;expression2)

{// JavaScript commands

}
While Loop:-

Syntax:-

while (condition)

// JavaScript commands

2. List the advantages of JavaScript.(APR.2014, APR.2016, NOV.2013, NOV.2014)


 -An Interpreted Language – JavaScript is an interpreted language, which requires no compilation
steps. This provides an easy development process
 Embedded within HTML – JavaScript does not require any special or separate editor for programs to
be written, edited or compiled. It can be written in any text editor like Notepad, along with appropriate
HTML tags and saved as filename.html
 Minimal Syntax – Easy to Learn – By learning just few commands and simple rules of syntax,
complete applications can be build using JavaScript
 Quick Development – Because JavaScript does not require any time-consuming compilations, scripts
can be developed in a short period of time.
 Designed for Simple, Small Programs – It is well suited to implement simple, small programs (for
example, a unit conversion calculator between miles and kilometers). Such programs can be easily
written and executed at an acceptable speed using JavaScript.
 Performance - JavaScript can be written such that the HTML files are fairly compact and quite small.
This minimizes storage requirements on the web server and download time for the client.
 Procedural Capabilities – Every programming language needs to support facilities such as Condition
checking, Looping, and Branching. JavaScript provides syntax, which can be used to add such
procedural capabilities to web page.
 Designed for Programming User Events – JavaScript supports Object/Event based programming.
JavaScript recognizes when a form Button is pressed. This event can have suitable JavaScript code
attached, which will execute when the Button Pressed event occurs.
 Easy debugging and testing – Being an interpreted language, scripts in JavaScript are tested line by
line and the errors are also listed as they encountered.
 Platform Independence – JavaScript is a programming language that is completely independent of the
hardware on which it works. It can be understood by any JavaScript enabled browser.

3. How to embed JavaScript in a webpage.(JULY 2012)

We can embed JavaScript code into an HTML document as follows:


<html>

<head>

<Script Language = “JavaScript”>

// JavaScript code snippet here

</Script>

</head>

</html>

 The <HEAD> tag makes an ideal place to create JavaScript variables and constants and so on.
 This is because the head of an HTML document is always processed before the body.
 Placing JavaScript memory variables, constants and user defined functions in the HEAD section of
the document will cause them to be defined before being used.
 This is important because any attempt to use a variable before it is defined, results in an error.

We can also place <SCRIPT> tag within the <BODY>….</BODY> tags of an HTML document as
follows:

<html>

<head>

<title> Untitled Page </title>

</head>

<body>

<Script Language = “JavaScript”>

// JavaScript code snippet here

</Script>

</body>

</html>

Example :-

<html>

<head><title> Welcome Text </title></head>

<body>

<Script Language = “JavaScript”>


document.write(“Hello World.!”);

</Script>

</body>

</html>

OUTPUT:-

Hello World.!

4. How do you differentiate between local variables and global variables in JavaScript.(NOV.2012)

LOCAL VARIABLES GLOBAL VARIABLES

1. A variable that is declared inside a function 1. A variable that is declared outside of a function
definition is called local variable definition is called a global variable

2.It has scope to that function only 2. It’s scope is throughout your program means its value is
accessible and modifiable throughout your program.

3. Local variables are deleted when the 3. Global variables are deleted when you close the browser
function is completed window (or tab), but remain available to new pages loaded
into the same window.
4. Accessed only by the statements, inside 4. Accessed by any statement in the entire program.
function in which they are declared

5.List the datatypes supported by JavaScript.(APR.2013,JULY 2014,NOV.2015)

JavaScript Language supports numeric, Boolean and string data. Apart from the above three types, object is
another important data type supported. As an open standard the null data and undefined data types are also
supported.
1. NUMBERS:-
The integer and floating point numeric data are called numbers. A number can be positive, negative or
zero.

Integers can be represented in decimal, octal and hexadecimal form. The octal integer begins with a zero
and hexadecimal integer begins with Ox or oX.

The following are some valid integers.


 45 = decimal value 45
 -015 = octal value )-15)8
 OX2A = hexadecimal value (2A)16

Floating point numbers can be represented either in decimal form or exponent form. The following are
some valid floating point numbers.
 0.78
 -10.2
2. BOOLEAN:-
JavaScript considers true or false values as Boolean values. In comparison 0 is consider as false and
any non-zero value as true. JavaScript automatically converts the Boolean values true and false into 1 and 0
when they are used in numerical expressions. Values 1 and 0 are not considered Boolean values in
JavaScript.
3. STRING:-
JavaScript provides built-in support for strings. A string is a sequence of zero or more characters that
are enclosed by double(“) or single(‘) quotes.
For example : “Rahul”, ’24, Sanjay Nagar, Bangalore’
4. OBJECT:-
As Javascript is an object oriented language, it is possible to define an object of a class. For example an
object of an employee class can be created using new operator as follows:
X=new employee(“Rajasekar”,45);
5. NULL AND UNDEFINED DATA TYPES:
A null value is one that has no value. A value that is undefined is a value held by a variable after it has
been created. It identifies a null, empty or nonexistent reference. It is used to set a variable to an initial value
that is different from other valid dates.

5. How arrays are declared and used in JavaScript.(APR.2013)


 Arrays are JavaScript objects that are capable of storing a sequence of values. These values are stored in
indexed locations within the array.
 The array element index starts with 0. Hence the last array element index number is one less that the
length of the array.

An array must be declared before it is used. An array can be declared using any one of the following
techniques.

arrayName=new Array(Array Length)

arrayName=new Array()

 In the first example, the array size is explicitly specified. Hence this array will hold a pre-determined set
of values.
 The second example creates an array of the size 0.

NOTE: JavaScript automatically extends the length of any array when new array elements are initialized.

Example;-

Cust_Orders = new Array()

Cust_Orders[50] = “Lion Pencils”

Cust_Orders[100] = “Steadler eraser”


Even if an array is initially created of a fixed length it may still be extended by referencing elements that are
outside the current size of the array. This is done with the same manner as with zero-length arrays.

6. What are the operators used in JavaScript? Give their hierarchy.(NOV.2013)

An operator is used to transform one or more values into a single resultant value. The values which the
operator is applied are referred to as operands.

JavaScript consists of the following operators

1. Arithmetic Operators

2. Logical Operators

3. Comparison Operators

4. String Operators

5. Assignment Operators

6. Conditional Expression Ternary Operator

7. Special Operators

1. ARITHMETIC OPERATORS:-

Arithmetic operators are the most familiar operators because they are used every day to solve common
math calculations. The arithmetic operators that JavaScript supports are:

OPERATOR DESCRIPTION

+ Addition

- Subtraction or Unary Negation

* Multiplication

/ Division

% Modulus

++ Return the value then Increment

-- Return the value then Decrement

2. LOGICAL OPERATORS:-

Logical operators are used to perform Boolean operators on Boolean operands AND, OR, NOT. The
logical operators that supported by JavaScript are:

OPERATOR DESCRIPTION
&& Logical AND

|| Logical OR

! Logical NOT

3. COMPARISON OPERATORS:-

Comparison operators are used to compare two values. The comparison operators supported by
JavaScript are:

OPERATOR DESCRIPTION

== Equal

=== Strictly Equal

!= Not Equal

!== Strictly Not Equal

< Less than

<= Less than or equal to

> Greater than

>= Greater than or equal to

4. STRING OPERATORS:-

String operators are those operators that are used to perform operations on strings. Currently JavaScript
supports only the string concatenation (+) operator. This operator is used to join two strings. For example,
“pq”+”ab” produces “pqab”.

5. ASSIGNMENT OPERATORS:-

The assignment operator is used to update the value of a variable. Some assignment operators are
combined with other operators to perform a computation on the value contained in a variable and then
update the variable with the new value. Some of the assignment operators supported by JavaScript are:

OPERATOR DESCRIPTION

= Sets the variable on the left of the = operator to the value of the
expression on its right.

+= Increments the variable on the left of the += operator by the


value of the expression on its right.

-= Decrements the variable on the left of the -= operator by the


value of the expression on its right.

*= Multiplies the variable on the left of the *= operator by the


value of the expression on its right.

/= Divides the variable on the left of the /= operator by the value


of the expression on its right.

%= Takes the modulus of the variable on the left of the %= operator


using the value of the expression on its right.

6. CONDITIONAL EXPRESSION TERNARY OPERATOR:-

JavaScript supports the conditional expression operator. They are ? and : The conditional expression
operator is ternary operator since it takes three operands, a condition to be evaluated and two alternative
values to be returned based on the truth or falsity of the condition

Syntax:-

Condition? Value1:Value2

The condition expressed must return a value true or false. If the condition is true, value1 is the result of the
expression, otherwise value2 is the result of the expression.

7. Discuss the usage of conditional expression (ternary operator) in JavaScript.


(APR. 20 12)

JavaScript supports the conditional expression operator. They are ? and : The conditional expression
operator is ternary operator since it takes three operands, a condition to be evaluated and two alternative values
to be returned based on the truth or falsity of the condition

Syntax:- Condition? Value1:Value2


The condition expressed must return a value true or false. If the condition
is true, value1 is the result of the expression; otherwise value2 is the result of the expression.

Consider the following example:

We have a person object that consists of a name, age, and driver property.

var person = {

name: 'tony',

age: 20,

driver: null

};
We want to test if the age of our person is greater than or equal to 16. If this is true, they’re old enough to drive
and driver should say 'Yes'. If this is not true, driver should be set to 'No'.

We could use an if statement to accomplish this:

if (person.age>= 16)

person.driver = 'Yes';

else

person.driver = 'No';

But what if I told you we could do the same exact thing in just one line of code? Well, here it is:

person.driver = person.age>=16 ?'Yes' : 'No';

This shorter code yields us the same result of person.driver = 'Yes';

8. How if statement is executed in JavaScript(JULY 2014)

Use the if statement to specify a block of JavaScript code to be executed if a condition is true.

Syntax

if (condition)

block of code to be executed if the condition is true

}
Example

/* Make a "Good day" greeting if the hour is less than 18:00 */

if (hour < 18) {

greeting = "Good day";

The result of greeting will be: Good day

9. How to use a ‘for’ loop in JavaScript.(JULY 2012)

The for loop is often the tool you will use when you want to create a loop.

The for loop has the following syntax:

for (statement 1; statement 2; statement 3)

code block to be executed

 Statement 1 is executed before the loop (the code block) starts.


 Statement 2 defines the condition for running the loop (the code block).
 Statement 3 is executed each time after the loop (the code block) has been executed.
Example:-

for (i = 0; i < 5; i++)

text += "The number is " + i + "<br>";

From the example above, you can read:

 Statement 1 sets a variable before the loop starts (var i = 0).


 Statement 2 defines the condition for the loop to run (i must be less than 5).
 Statement 3 increases a value (i++) each time the code block in the loop has been executed
10. Show how to create functions in JavaScript.(NOV. 2012)
 A JavaScript function is a block of code designed to perform a particular task.
 A JavaScript function is executed when "something" invokes it (calls it).

Syntax:-

function name(parameter1, parameter2, parameter3)

code to be executed

 A JavaScript function is defined with the function keyword, followed by a name, followed by
parentheses ().
 Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).
 The parentheses may include parameter names separated by commas:(parameter1, parameter2, ...)
 The code to be executed, by the function, is placed inside curly brackets: {}
 Function parameters are listed inside the parentheses () in the function definition.
 Function arguments are the values received by the function when it is invoked.
 Inside the function, the arguments (the parameters) behave as local variables.
 A Function is much the same as a Procedure or a Subroutine, in other programming languages.

Example

function myFunction(p1, p2)

return p1 * p2; // The function returns the product of p1 and p2

10 MARKS
1. Elaborate the control structures in JavaScript with an example.(APR. 2013)

Control Structure:-

Control structure actually controls the flow of execution of a program. Following are the several control
structure supported by JavaScript.

1. if … else
2. switch case
3. do while loop
4. while loop
5. for loop

1. The if Statement

Use the if statement to specify a block of JavaScript code to be executed if a condition is true.

Syntax

if (condition)

block of code to be executed if the condition is true

}
Example

/* Make a "Good day" greeting if the hour is less than 18:00 */

if (hour < 18) {

greeting = "Good day";

The result of greeting will be:

Good day

2. Switch case

The basic syntax of the switch statement is to give an expression to evaluate and several different
statements to execute based on the value of the expression. The interpreter checks each case against the
value of the expression until a match is found. If nothing matches, a default condition will be used.

Syntax:-

switch (expression)

case condition 1: statement(s)

break;

case condition 2: statement(s)

break;

...

case condition n: statement(s)

break;
default: statement(s)

Example

<script type="text/javascript">

<!--

var grade='A';

document.write("Entering switch block<br/>");

switch (grade)

case 'A': document.write("Good job<br/>");

break;

case 'B': document.write("Pretty good<br/>");

break;

case 'C': document.write("Passed<br/>");

break;

case 'D': document.write("Not so good<br/>");

break;

case 'F': document.write("Failed<br/>");

break;

default: document.write("Unknown grade<br/>")


}

document.write("Exiting switch block");

//-->

</script>

3. While loop:-

The purpose of a while loop is to execute a statement or code block repeatedly as long as expression is
true. Once expression becomes false, the loop will be exited.

Syntax

while (expression)

Statement(s) to be executed if expression is true

Example

<script type="text/javascript">

<!--

var count = 0;

document.write("Starting Loop" + "<br/>");

while (count < 10){

document.write("Current Count : " + count + "<br/>");


count++;

document.write("Loop stopped!");

//-->

</script>

OUTPUT:-

Starting Loop

Current Count : 0

Current Count : 1

Current Count : 2

Current Count : 3

Current Count : 4

Current Count : 5

Current Count : 6

Current Count : 7

Current Count : 8

Current Count : 9

Loop stopped!

4. Do while loop:-

The do...while loop is similar to the while loop except that the condition check happens at the end of the
loop. This means that the loop will always be executed at least once, even if the condition is false.

Syntax

do

Statement(s) to be executed;

} while (expression);
Example

<script type="text/javascript">

var count = 0;

document.write("Starting Loop" + "<br/>");

do{

document.write("Current Count : " + count + "<br/>");

count++;

}while (count < 0);

document.write("Loop stopped!");

</script>

OUTPUT:-

Starting Loop

Current Count : 0

Loop stopped!

5. The for loop:-

The for loop is often the tool you will use when you want to create a loop.

The for loop has the following syntax:

for (statement 1; statement 2; statement 3)


{

code block to be executed

 Statement 1 is executed before the loop (the code block) starts.


 Statement 2 defines the condition for running the loop (the code block).
 Statement 3 is executed each time after the loop (the code block) has been executed.

Example:-

for (i = 0; i < 5; i++)

text += "The number is " + i + "<br>";

From the example above, you can read:

 Statement 1 sets a variable before the loop starts (var i = 0).


 Statement 2 defines the condition for the loop to run (i must be less than 5).
 Statement 3 increases a value (i++) each time the code block in the loop has been executed

2. Discuss the datatypes supported in JavaScript.(NOV.2013,NOV.2014,JULY 2014)

JavaScript Language supports numeric, Boolean and string data. Apart from the above three types,
object is another important data type supported. As an open standard the null data and undefined data types
are also supported.

1. NUMBERS:-
The integer and floating point numeric data are called numbers. A number can be positive, negative or
zero.
Integers can be represented in decimal, octal and hexadecimal form. The octal integer begins with a zero
and hexadecimal integer begins with Ox or oX.

The following are some valid integers.


 45 = decimal value 45
 -015 = octal value )-15)8
 OX2A = hexadecimal value (2A)16

Floating point numbers can be represented either in decimal form or exponent form. The following are
some valid floating point numbers.
 0.78
 -10.2

2. BOOLEAN:-
JavaScript considers true or false values as Boolean values. In comparison 0 is consider as false and
any non-zero value as true. JavaScript automatically converts the Boolean values true and false into 1 and 0
when they are used in numerical expressions. Values 1 and 0 are not considered Boolean values in
JavaScript.

3. STRING:-
JavaScript provides built-in support for strings. A string is a sequence of zero or more characters that
are enclosed by double(“) or single(‘) quotes.
For example : “Rahul”, ’24, Sanjay Nagar, Bangalore’

4. OBJECT:-
As Javascript is an object oriented language, it is possible to define an object of a class. For example an
object of an employee class can be created using new operator as follows:
X=new employee(“Rajasekar”,45);

5. NULL AND UNDEFINED DATA TYPES:


A null value is one that has no value. A value that is undefined is a value held by a variable after it has
been created. It identifies a null, empty or nonexistent reference. It is used to set a variable to an initial value
that is different from other valid dates.

3. What are the advantages of JavaScript and Expressions.(NOV.2015)

ADVANTAGES:-

 An Interpreted Language – JavaScript is an interpreted language, which requires no compilation steps.


This provides an easy development process
 Embedded within HTML – JavaScript does not require any special or separate editor for programs to
be written, edited or compiled. It can be written in any text editor like Notepad, along with appropriate
HTML tags and saved as filename.html
 Minimal Syntax – Easy to Learn – By learning just few commands and simple rules of syntax,
complete applications can be build using JavaScript
 Quick Development – Because JavaScript does not require any time-consuming compilations, scripts
can be developed in a short period of time.
 Designed for Simple, Small Programs – It is well suited to implement simple, small programs (for
example, a unit conversion calculator between miles and kilometers). Such programs can be easily
written and executed at an acceptable speed using JavaScript.
 Performance - JavaScript can be written such that the HTML files are fairly compact and quite small.
This minimizes storage requirements on the web server and download time for the client.
 Procedural Capabilities – Every programming language needs to support facilities such as Condition
checking, Looping, and Branching. JavaScript provides syntax, which can be used to add such
procedural capabilities to web page.
 Designed for Programming User Events – JavaScript supports Object/Event based programming.
JavaScript recognizes when a form Button is pressed. This event can have suitable JavaScript code
attached, which will execute when the Button Pressed event occurs.
 Easy debugging and testing – Being an interpreted language, scripts in JavaScript are tested line by
line and the errors are also listed as they encountered.
 Platform Independence – JavaScript is a programming language that is completely independent of the
hardware on which it works. It can be understood by any JavaScript enabled browser.

Expressions:

 An expression is any valid unit of code that resolves to a value.


 Every syntactically valid expression resolves to some value but conceptually, there are two types of
expressions: with side effects (for example: those that assign value to a variable) and those that in some
sense evaluate and therefore resolve to a value.
 The expression x = 7 is an example of the first type. This expression uses the = operatorto assign the
value seven to the variable x. The expression itself evaluates to seven.
 The code 3 + 4 is an example of the second expression type. This expression uses the + operator to add
three and four together without assigning the result, seven, to a variable.

JavaScript has the following expression categories:

 Arithmetic: evaluates to a number, for example 3.14159. (Generally uses arithmetic operators.)
 String: evaluates to a character string, for example, "Fred" or "234". (Generally uses string operators.)
 Logical: evaluates to true or false. (Often involves logical operators.)
 Primary expressions: Basic keywords and general expressions in JavaScript.
 Left-hand-side expressions: Left values are the destination of an assignment.

4. Explain the structure of JavaScript. What are its advantages.(APR.2012)

JAVASCRIPT STRUCTURE:-

 JavaScript syntax is embedded into an HTML file.


 A browser reads HTML files and interprets HTML tags.
 Since all JavaScripts need to be included as an integral part of an HTML document when required, the
browser needs to be informed that specific sections of HTML code is JavaScript.
 The browser will then use its built in JavaScript engine to interpret this code.
SYNTAX:-

<SCRIPT LANGUAGE=”JavaScript”>

// JavaScript code snippet here

</SCRIPT>

 The browser is given this information using the HTML tags <SCRIPT>….</SCRIPT>.
 The <SCRIPT> tag marks the beginning of a snippet of scripting code.
 The paired </SCRIPT> tag marks the end of a snippet of scripting code.

Like most other HTML tags, the <SCRIPT> tag takes in an optional attribute, as listed below.

Attributes Description

Language Indicates the scripting language used for


writing the snippet of scripting code.

ADVANTAGES:-

 An Interpreted Language – JavaScript is an interpreted language, which requires no compilation steps.


This provides an easy development process
 Embedded within HTML – JavaScript does not require any special or separate editor for programs to
be written, edited or compiled. It can be written in any text editor like Notepad, along with appropriate
HTML tags and saved as filename.html
 Minimal Syntax – Easy to Learn – By learning just few commands and simple rules of syntax,
complete applications can be build using JavaScript
 Quick Development – Because JavaScript does not require any time-consuming compilations, scripts
can be developed in a short period of time.
 Designed for Simple, Small Programs – It is well suited to implement simple, small programs (for
example, a unit conversion calculator between miles and kilometers). Such programs can be easily
written and executed at an acceptable speed using JavaScript.
 Performance - JavaScript can be written such that the HTML files are fairly compact and quite small.
This minimizes storage requirements on the web server and download time for the client.
 Procedural Capabilities – Every programming language needs to support facilities such as Condition
checking, Looping, and Branching. JavaScript provides syntax, which can be used to add such
procedural capabilities to web page.
 Designed for Programming User Events – JavaScript supports Object/Event based programming.
JavaScript recognizes when a form Button is pressed. This event can have suitable JavaScript code
attached, which will execute when the Button Pressed event occurs.
 Easy debugging and testing – Being an interpreted language, scripts in JavaScript are tested line by
line and the errors are also listed as they encountered.
 Platform Independence – JavaScript is a programming language that is completely independent of the
hardware on which it works. It can be understood by any JavaScript enabled browser
5. Give the purpose of dialog box

JavaScript provides the ability to pickup user input or display small amount of text to the user by the
dialog boxes. These dialog boxes appear as second windows and their content depends on the information
provided by the user.

There are 3 types of dialog boxes provided in JavaScript:

THE ALERT DIALOG BOX:

 The simplest way to direct small amounts of textual output to a browser’s window is to use an alert
dialog box.
 The JavaScript alert() method takes a string as an argument and displays an alert dialog box in the
browser window when invoked by appropriate JavaScript.
 The alert dialog box displays the string passed to the alert() method, as well as an OK button .
 The alert dialog box can be used to display a cautionary message or display some information. For
instance:
1. A message is displayed to the user when incorrect information is keyed in a form.
2. An invalid result is the output of a calculation
3. A warning that a service is not available on a given date/time.

Syntax:-

alert(“<Message>”);

Example:-

alert(“Click OK to Continue”);

Example Program:-

<HTML>
<HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<SCRIPT language=”JavaScript”>
alert(“Welcome to my website!”);
</SCRIPT>
</BODY>
</HTML>

THE PROMPT DIALOG BOX:-

 JavaScript provides a prompt dialog box for this. The prompt() method instantiates the prompt dialog
box which displays a specified message.
 In addition, the prompt dialog box also provides a single data entry field, which accepts user input.
Thus, a prompt dialog box:
1. Displays a predefined message
2. Displays a textbox and accepts user input.
3. Displays the OK and the Cancel button.
 When the prompt() method is used to instantiate and use a dialog box the method requires two blocks of
information:
1. A message to be displayed as a prompt to the user.
2. Any message to be displayed in the textbox (this is optional)

Syntax:-

prompt(“<Message>”,”<Default value>”);

Example:-

prompt(“Enter Your Favorite color:”,”Blue”);

Example Program:-

<HTML>
<HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<SCRIPT language=”JavaScript”>
document.write(prompt(“Enter your name:”,”Name”));
document.write(“&nbsp;Welcome to my homepage!”);
</SCRIPT>
</BODY>
</HTML>

THE CONFIRM DIALOG BOX:-

 JavaScript provides a third type of dialog box called the confirm dialog box.
 As the name suggests, this dialog box serves as a technique for confirming user action.
 The confirm dialog box displays the following information:
1. A pre-defined message
2. OK and Cancel Button
 Display of a confirm dialog box thus requires only one block of information: A pre-defined message to
be displayed.

Syntax:-

confirm(“<Message>”);

Example:-

Confirm(“Are you sure you want to exit out of the system”);

Example Program:-

<HTML>
<HEAD><TITLE>Example</TITLE></HEAD>
<BODY>
<SCRIPT language=”JavaScript”>
var txt;
var r = confirm("Press a button!");
if (r == true)
{
txt = "You pressed OK!";
}
else
{
txt = "You pressed Cancel!";
}
</SCRIPT>
</BODY>
</HTML>

The above program displays a confirmation box, and output what the user clicked.

6. Explain in detail the concept of array with example.(NOV.2012)

 Arrays are JavaScript objects that are capable of storing a sequence of values. These values are stored in
indexed locations within the array.
 The array element index starts with 0. Hence the last array element index number is one less that the
length of the array.
 An array must be declared before it is used. An array can be declared using any one of the following
techniques.

arrayName=new Array(Array Length)

arrayName=new Array()

 In the first example, the array size is explicitly specified. Hence this array will hold a pre-determined set
of values.
 The second example creates an array of the size 0.
 JavaScript automatically extends the length of any array when new array elements are initialized.

Example;-

Cust_Orders = new Array()

Cust_Orders[50] = “Lion Pencils”

Cust_Orders[100] = “Steadler eraser”

Even if an array is initially created of a fixed length it may still be extended by referencing elements that
are outside the current size of the array. This is done with the same manner as with zero-length arrays.

Example Program:-
You can create an array in javascript as follows (in this example you can see an entire .html file; later on
we'll just look at the javascript part)

<html>

<head><title>Basic Javascript Array Example</title>

<script language="javascript">

// Empty array

var empty = [];

// Array containing initial elements.

var fruits = ['apple', 'orange', 'kiwi'];

alert(fruits[1]);

</script></head>

<body>

</body>

</html>

8. Explain the concept of constructor function in JavaScript(JULY 2014,APR.2015,APR. 2016)

Constructor Functions:-

 Constructor functions are the equivalent of classes in many programming languages. Sometimes people
will refer to them as as reference types, classes, data types, or simply constructors.
 If you aren’t familiar with classes, they are a construct that allows you to specify some properties and
behaviors (functions), and multiple objects can be created with those properties and behaviors.
 A common analogy you’ll often hear is, a class is to a blueprint as an object is to a house. Multiple
houses can be created from a single blueprint, as multiple objects can be created from a class.

Let’s define a constructor function:

function Person(name,position)

{
this.name=name;

this.position=position;

There is really nothing special about this function except that the function name starts with a
capital letter.

This isn’t mandatory, but it is popular convention so that other developers know to invoke it as a
constructor function.

Constructor functions instead are invoked using the new operator:

vardavid= new Person(‘David Tang’,’Lecturer’);

varpatrick= new Person(‘Patrick Dent,’Associate Professor’);

Here we are constructing two Person objects.

When a constructor function is invoked with the new keyword, this refers to the object that is
being constructed. Note, if a constructor is invoked without the new keyword, this will point to the
global object, which is the window object in the browser. This will end up creating properties on the
window object (also known as global variables), which is not a recommended practice.

Methods:-

Methods can be defined on constructor functions by assigning a function to a property.

function Person(name)

this.name=name;

this.hi=function()

Console.log(‘Hi! My name is’ +this.name);

};

vareminem=new Person(‘Slim Shady’);

eminem.hi(); //Hi! My name is Slim Shady

In this example, the hi property is assigned a function. When it is invoked off of a Person object, the
keyword this will correspond to the newly constructed Person object.

9. Describe the operator and expression in JavaScript.(JULY 2012)


An operator is used to transform one or more values into a single resultant value. The values which the
operator is applied is referred to as operands.

JavaScript consists of the following operators

1. Arithmetic Operators

2. Logical Operators

3. Comparison Operators

4. String Operators

5. Assignment Operators

6. Conditional Expression Ternary Operator

7. Special Operators

1. ARITHMETIC OPERATORS:-

Arithmetic operators are the most familiar operators because they are used every day to solve common math
calculations. The arithmetic operators that JavaScript supports are:

OPERATOR DESCRIPTION

+ Addition

- Subtraction or Unary Negation

* Multiplication

/ Division

% Modulus

++ Return the value then Increment

-- Return the value then Decrement

2. LOGICAL OPERATORS:-

Logical operators are used to perform Boolean operators on Boolean operands AND, OR, NOT. The
logical operators that supported by JavaScript are:

OPERATOR DESCRIPTION

&& Logical AND

|| Logical OR

! Logical NOT

3. COMPARISON OPERATORS:-
Comparison operators are used to compare two values. The comparison operators supported by
JavaScript are:

OPERATOR DESCRIPTION

== Equal

=== Strictly Equal

!= Not Equal

!== Strictly Not Equal

< Less than

<= Less than or equal to

> Greater than

>= Greater than or equal to

4. STRING OPERATORS:-

String operators are those operators that are used to perform operations on strings. Currently JavaScript
supports only the string concatenation (+) operator. This operator is used to join two strings. For
example, “pq”+”ab” produces “pqab”.

5. ASSIGNMENT OPERATORS:-

The assignment operator is used to update the value of a variable. Some assignment operators are
combined with other operators to perform a computation on the value contained in a variable and then
update the variable with the new value. Some of the assignment operators supported by JavaScript are:

OPERATOR DESCRIPTION

= Sets the variable on the left of the = operator to the


value of the expression on its right.

+= Increments the variable on the left of the +=


operator by the value of the expression on its right.

-= Decrements the variable on the left of the -=


operator by the value of the expression on its right.

*= Multiplies the variable on the left of the *= operator


by the value of the expression on its right.

/= Divides the variable on the left of the /= operator by


the value of the expression on its right.

%= Takes the modulus of the variable on the left of the


%= operator using the value of the expression on its
right.

6. CONDITIONAL EXPRESSION TERNARY OPERATOR:-

JavaScript supports the conditional expression operator. They are ? and : The conditional expression
operator is ternary operator since it takes three operands, a condition to be evaluated and two alternative
values to be returned based on the truth or falsity of the condition

Syntax

Condition? Value1:Value2

The condition expressed must return a value true or false. If the condition is true, value1 is the result of
the expression, otherwise value2 is the result of the expression.

EXPRESSIONS:-

 An expression is any valid unit of code that resolves to a value.


 Every syntactically valid expression resolves to some value but conceptually, there are two types of
expressions: with side effects (for example: those that assign value to a variable) and those that in some
sense evaluate and therefore resolve to a value.
 The expression x = 7 is an example of the first type. This expression uses the = operatorto assign the
value seven to the variable x. The expression itself evaluates to seven.
 The code 3 + 4 is an example of the second expression type. This expression uses the + operator to add
three and four together without assigning the result, seven, to a variable.
JavaScript has the following expression categories:
 Arithmetic: evaluates to a number, for example 3.14159. (Generally uses arithmetic operators.)
 String: evaluates to a character string, for example, "Fred" or "234". (Generally uses string operators.)
 Logical: evaluates to true or false. (Often involves logical operators.)
 Primary expressions: Basic keywords and general expressions in JavaScript.
 Left-hand-side expressions: Left values are the destination of an assignment.

UNIT-III
2 MARKS
1. Define: cookies? (NOV.2013, NOV. 2014, JULY 2012, JULY 2014,JULY 2016)
 A Cookie is a small text file that the browser creates and stores on the hard drive of your machine.
 Cookie is just one or more pieces of information stored as text string.
 Once a cookie has been stored, the information in the cookie will be sent back to the web server
each time your browser request data
(e.g. web pages and multimedia files)from the server
syntax :
set cookie = "name=value; expires=date; path=path; domain=domain; secure";

2. What is meant by Event Handling? (NOV.2014, APR.2014, APR. 2016)


 The Event handler specifies which JavaScript code to execute.
 Often, event handlers are placed within the HTML tag which creates the object on which the
event acts:
Syntax:
<tag attribute1 attribute2 onEventName=”JavaScript code;”>
Example
<a href=”onMouseOver=”popupFun();”>

3. Give the purpose of navigator object? (APR. 2013)

 The Navigator object is designed to contain information about the version of Netscape Navigator
which is being used.
 It contains information about different aspects of the browser.

4. What are the basic model objects supported in Java Script?

 Language Objects – Objects provided by the language and are not dependent on other objects.
 Navigator Objects-Objects provided by the client browser.These objects are all sub objects to the
navigator object.
 Document Object – The JavaScript Document object is the container for all HTML and BODY
objects associated within the HTML tags of an HTML document.
 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.
 Window Object - The JavaScript Window Object is the highest level JavaScript object which
corresponds to the web browser window.

5-MARKS

1. Write a note on cookies and screen object? (NOV.2014, APR. 2014)


Cookies:
 A Cookie is a small text file that the browser creates and stores on the hard drive of your machine.
 Cookie is just one or more pieces of information stored as text string.
 Once a cookie has been stored, the information in the cookie will be sent back to the web server
each time your browser request data(e.g. web pages and multimedia files)from the server
 The most common use of a cookie is to store information about the user and preferences the user
makes.
 Creating cookies with ASP.NET is simply and straight forward.
 The System.Web namespace offers a class called HttpCookie to create cookies.
 The property used to read cookies is Request.Cookies(“CookieName”) and to write is
Response.Cookies(“CookieName”).

Example:

<asp: Label ID=”lblShowCookie” Runat=”server” /><br><br>

<asp: TextBox ID=”txtCookies” Runat=”server” /><br><br>

<asp: Rutton ID=”cmdCookies” Runat=”server” Text=”ShowCookies” />


 Cookies that are erased when you close your browser are called “session cookies”.
 Cookies that last for a longer time period are called”persistent cookies”.
 The JavaScript cookie is a document object. The following parameters specify a cookie:
 name=value
 expires=date
 path=path
 domain=domainname
 secure

Screen Object

 It contains information about the client’s display screen.


Screen Syntax:
screen.availHeight screen.availWidth screen.colorDepth screen.height screen.pixelDepth screen.width
Example
<HTML>
<body>
<script type="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>

Properties of Screen Object:

 width – gives the width of the screen.


 Height – gives the height of the screen.
 avail Width – gives the available width of the screen.
 avail Height – gives the available height of the screen.
 color depth – gives the color depth of the screen.

2. Write about Anchor?

The anchors collection returns an array of all the anchors in the current document.

Syntax

document.anchors[].property

Example
<html>
<body>
<a name=" java ">java</a><br />
<a name="c++">C++</a><br />
<script type="javascript">
document.write(document.anchors.length);</script></p></body>

</html>

3. What is meant by Event Handling?Explain? (NOV.2014, NOV. 2015, APR. 2012)

 The Event handler specifies which JavaScript code to execute.


 Often, event handlers are placed within the HTML tag which creates the object on which the
event acts:
Syntax:
<tag attribute1 attribute2 onEventName=”JavaScript code;”>
Example
<a href=”onMouseOver=”popupFun();”>
4. Write about form object?

 Forms give life to static pages by providing an interface users can interact with through controls.
 You can only place button,text, or other UI objects within the confines of a form.
 The form object is your means of inter-acting with this HTML element in your scripts.
i. Button objects
ii. Select object
iii. Checkbox object
iv. Radio object
v. Text object
vi. Textarea object
vii. Password object

Syntax

<form [“NAME=formname”] [ACTION=”serverURL”] [ENCTYPE=”encodingType”]


[METHOD=GET | POST]

[TARGET=”windowName”] [onSubmit=”methosName”]>

</form>

Example

<HTML>

<HEAD><Title>Form example</Title></HEAD>

<Body>

<FORM NAME=form1” ACTION=”http://www.cybersoftsystems.net/cgi-bin/guest.p1”


METHOD=POST onSubmit=”alert(‘ Data Submitted’)”>

<Input Type=Text Name=t1 Size=20>

<Input Type=Text Name=t2 Size=20>

<Br>

<Input Type=Submit>

</FORM>

</BODY>

</HTML>

Properties of Form Object:

 Action
 Encoding
 Length
 Method
 Name
 Target
 Button checkbox
 fileUpload
 hidden
 password
 radio
 reset
 select
 submit
 text
 textarea

10-MARKS
1. Explain the following Objects. (APR.2014, JULY 2014)
a) Browser Object(APR. 2013,APR. 2016)
b) Navigator Object
Ans: a) Browser object- REFER Q.NO.1(10-MARKS) – WINDOW OBJECT, REFER .NO.1(5-MARKS) –
SCREEN OBJECT

b) 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

platform Returns for which platform the browser is compiled

UserAgent Returns the user-agent header sent by the browser to the serve
The Navigator object is designed to contain information about the version of Netscape Navigator which is being
used. However, it can also be used with Internet Explorer. All of its properties, which are read-only, contain
information about different aspects of the browser.

Navigator Syntax

navigator.appCodeName

navigator.appName
navigator.appVersion

navigator.cookieEnabled

navigator.platform

navigator.userAgent

Example

<html> <body>

<script type="javascript">

document.write("Browser CodeName: " + navigator.appCodeName);

document.write("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>

2. Describe the document Object model in javascript? (APR. 2013, APR. 2016)

 JavaScript handles the HTML documents and the related objects such as windows, forms and screen in a
specified hierarchy.
 This hierarchy is called the Document Object Model(DOM) are directly related to the browser.
 The properties of the objects covered in the DOM get their values supplied by the browser.
 Each HTML document loaded into a browser window becomes a Document object.
 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[] Returns an array of all the anchors in the document
forms[] Returns an array of all the forms in the document
images[] Returns an array of all the images in the document
links[] Returns an array of all the links in the document
Anchors
The anchors collection returns an array of all the anchors in the current document.
Syntax:
document.anchors[].property
Example
<html>
<body>
<a name=" java ">java</a><br />
<a name="c++">C++</a><br />
<script type="text/javascript">
document.write(document.anchors.length);
</script>
</p>
</body>
</html>
forms
The forms collection returns an array of all the forms in the current document
Syntax:
document.forms[].property
Example
<html>
<body>
<form name="Form1">
</form>
<form name="Form2">
</form>
<p>Number of forms:
<script type="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="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 <a
href=""> tags and <area> tags.
Syntax
document.links[].property
Example
<html>
<body>
<a href="images.html">
Images</a>
<p>Number of areas/links:
<script type="javascript">
document.write(document.links.length);
</script>
</p>
</body>
</html>

3. Discuss about Built in object and User defined object?


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:
a. The String object,
b. The Math object, and
c. 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);
a. String Object Methods:
The flexible and power of the string object resets in the wide variety of methods available to manipulate the
contents of the string

Methods Description

Big( ) Surrounds the string with the HTML big tag


Blink( ) Surrounds the string with the HTML blink tag
Bold( ) Surrounds the string with the HTML bold tag
Charat( ) Given an index as an argument, returns the character at the
Specified index.
Italics( ) Surrounds the string with the HTML<I> tag.
To lowercases( ) Makes the entire string lowercase.
To uppercases( ) Makes the entire string uppercase.

Properties:
The string object has only one property:

Property Description

Length An integer value indicating the number of characters in the string.


b. Math Object:
The math object provides methods and properties to move beyond simple arithmetic manipulations
offered by arithmetic operators.
Properties:
Property Description

E Euler’s constant – the base of natural logarithms.


LN10 The natural logarithms of 10 (roughly 2.302)
LN2 The natural logarithms of 2 (roughly 0.693).
PI The ratio of the circumference of a circle to the diameter of the same
circle (roughly 3.1415).

Methods:

Methods Description

Abs( ) Calculates the absolute value of a number.


Cell( ) Returns the next integer greater than or equal to a number.
Cos( ) Calculates the cosine of a number.
Floor( ) Returns the next integer less than or equal to a number.
Tan( ) Calculates the tangent of a number.
Random( ) Returns the random number between zero and one.
Sin( ) Calculates the sine of a number.
Sqrt( ) Calculates the square root of a number.

c. Date Object:
The Date object enables JavaScript Programmers to create an object that contains information about a
particular date and provides a set of methods to work with that information.
To create an instance of the data object; use new keyword
Syntax:
var my_date=new Date (<parameters>);

Methods:

Method Description

SetDate( ) Returns the day of the month as an integer from 1 to 31


setData( ) Sets the day of the month based on an integer arguments from 1 to
31
setHours ( ) Returns the hours as an integer from 0 and 23
getTime ( ) Returns the number of milliseconds since 1 january 1970 at
00:00:00
SetTimer ( ) Sets the time based on an argument representing the number of
milliseconds since 1 January 1970 at 00:00:00
setHours ( ) Sets the hour based on an argument from 0 to 23.

User Defined Object


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="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>
</html>

4. Give detail note on Event Handling? (JULY 2012)

Refer Q.No:3 (in 5 Marks)

5. Discuss the form object in detail ?(NOV.2012, APR.2012)

 Forms give life to static pages by providing an interface users can interact with through controls.
 we can only place button, text, or other UI objects within the confines of a form.
 The form object is your means of inter-acting with this HTML element in your scripts.
viii. Button objects
ix. Select object
x. Checkbox object
xi. Radio object
xii. Text object
xiii. Textarea object
xiv. Password object

Syntax

<form [“NAME=formname”] [ACTION=”serverURL”] [ENCTYPE=”encodingType”]


[METHOD=GET | POST] [TARGET=”windowName”] [onSubmit=”methosName”]>

</form>

Properties of Form Object:

 Action
 Encoding
 Length
 Method
 Name
 Target
 Button checkbox
 fileUpload
 hidden
 password
 radio
 reset
 select
 submit
 text
 textarea
 elements[]

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.
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.
Example:

<HTML>

<HEAD><Title>Form example</Title></HEAD>

<Body>

<FORM NAME=form1” ACTION=”http://www.cybersoftsystems.net/cgi-bin/guest.p1”


METHOD=POST onSubmit=”alert(‘ Data Submitted’)”

<Input Type=Text Name=t1 Size=20>

<Input Type=Text Name=t2 Size=20><Br>

<Input Type=Submit>

</FORM>

</BODY>

</HTML>

6. Explain about object in HTML and cookies?


Refer any objects from above questions, Refer Q.No.1(5-mark) for Cookies.

7. Explain the usage of window object?

Window Object

The window object is the top-level object of the object hierarchy. Whenever an object method or property is
referenced in a script without the object name and dot prefix it is assumed by JavaScript to be a member of the
window object. This means, for example, that when calling the window alert() method to display an alert dialog
the window. Therefore the following method calls achieve the same thing:

window.alert(); or alert()

JavaScript Window Object Properties

The JavaScript window object contains a number of properties that can be inspected and used in a script:

 window.closed - Used when handling multiple windows, this property indicates whether a window has
been closed or not.

 window.defaultstatus / window.status - defaultstatus specifies the default message displayed in the


browser status bar. status specifies a temporary message to display in the browser status bar in place of
the default. Disabled in many browsers.

 window.frames[] - If the window contains frames this array holds the array of frame objects (see
JavaScript Arrays details on accessing arrays).

 window.name - Windows opened by a script must be given a name. This property contains the name of
the corresponding window object.

 window.opener - When a window has been opened in a script contained in another window, this
property of the child window contains a reference window which opened it.

 window.parent - When working with frames in a window this property contains a reference to the
window object that contains the frame.
 window.screen - An object which contains information about the screen on which the window is
displays (properties contained in this object include height, width, availHeight, availWidth and
colorDepth).

 window.self - A reference to the current window.

 window.top - A reference to the top-level window when working with frames.

Opening and Closing of Browser Windows using JavaScript

A new browser window can be opened from a JavaScript script using the open() method of the window object.

syntax for opening a new window:

newWindowObj = window.open("URL", "WindowName", "feature, feature, feature ... ");

The following provides an explanation of the arguments passed through to the open() method:

 URL - Specifies the URL of the web page to be loaded into the new window. If no URL is specified a
blank window is loaded.

 WindowName - Specifies the window name and is used to refer to the window.

 features - A comma separated list of features that allow you to customize the appearance of the window.
Options are:

Setting Explanation
width Specifies the initial width of the browser client window (see innerWidth for size of content area)
height Specifies the initial height of the browser client window (see innerHeight for size of content area)
innerWidth Specifies the initial width of the window content area
innerHeight Specifies the initial height of the window content area
outerWidth Specifies the initial width of the navigator window
outerHeight Specifies the initial height of the navigator window
toolbar Specifies whether the window should contain the browser toolbar or not
status Specifies whether the window should contain the browser status bar or not
dependent Specifies whether the window should close in unison with its parent window
menubar Specifies whether the window should contain the browser menubar

The height, width and position features are set using numbers. The remaining feature options can be set using
true or false values (also yes, no and 1 and 0 can be used in place of true and false). An absent attribute is
considered to be false.

Example:

newWindowObj = window.open("URL", "WindowName", "toolbar=0, menubar=1, innerHeight=200,


innerWidth=300");

Closing Browser Windows using JavaScript

A window can be closed using the window object's close() method. The name of the window (specified in the
open() method) should be referenced when performing a close so that you are certain to close the correct
window.
Example:

The following code creates a new window and creates a pushbutton which, when clicked, closes the new
window:

<script language="JavaScript" type="text/javascript">

newWindowObj = window.open ("", "MyWindow");

</script>

<form action="null">
<input type="button" value="Close Window" onclick="newWindowObj.close()" />
</form>

It is also possible to close the window that opened the current window using the opener property of the current
window object:

window.opener.close()

This will close the window that opened the window in which the above script is run.

UNIT-IV
2 MARKS
1. What is meant by Event Handling? (NOV. 2014,APR.2014)

JavaScript’s response to one of the user initiated events is called event handling.

Example: JavaScript handle the event by calling a function that will perform some designated task, such
as to open a new window or bring a window into focus, perform a calculation, or submit a fill-out form.

Syntax: Name_of_handler=”JavaScript code here”

2. How page event is defined in Asp.NET? (NOV. 2013,APR. 2014)

ASP.NET uses an event-driven model of programming. This model of ASP.NET defines a sequence of
events that are fired during the life cycle of a web page.

3. Define DataGrid? (NOV.2013,APR.2014)


DataGrid control to display data on the web page. It is used to display data in scrollable grid. It requires
data source to populate data in the grid.

Property: Description:

a. id A unique id for the control


b. runat Specifies that the control is a server control.
(Must be set to “server”)
4. Mention the need of radio button?

We can add individual radio button to your page one by one, using the RadioButton control.
RadioButton are grouped together using the GroupName property. Only one RadioButton control from
each group can be selected at a time.

Example: <asp:RadioButton id=”radBsc” GroupName=”Courses”Text=”bsc” runat=”server”/>

5. List the properties of PageEvent?

We have two properties which we an work with the page object. They are

IsPostBack Property

IsValid Property

6. List any four HTML Server controls? (APR-2016)

HTML Server controls are

 HtmlAnchor
 HtmlTable
 HtmlButton
 HtmlForm

7. What is meant by Repeater control? (APR-2013,APR. 2016)

Repeater control displays data using user-defined layout. It just repeats the HTML and ASP.NET
controls that is placed inside a template block.

Example: <asp:Repeater id=”repeat1” runat=”server”>

5 MARKS
8. Expain the following: (APR-2015)
a. Anchor
b. Table
c. Forms
d. Files

a.Anchor:- Controls an <a> HTML element

Property Description

Attributes Returns all attributes name and value pairs of the element

Disabled A Boolean value that indicates whether or not the control should be disabled.
Default is false.

Href The URL target of the link


Id A unique id for the control

InnerHtml Sets or returns the content between the opening and closing tags of the
HTML element

InnerText Sets or returns all text between the opening and closing tags of the HTML
element.

Name The name of the anchor

OnServerClick The name of the function to be executed when the link is clicked

Runat Specifies that the control is a server control. Must be set to “server”

Style Sets or returns the CSS properties that are applied to the control

TagName Retruns the element tag name

Target The target window to open

Title A title to be displayed by the browser

Visible A Boolean value that indicates whether or not the control should be
visible

b. Tables: Controls a <table> HTML element

HtmlTable Cell Controls<td> and <th> HTML elements

HTMLTableRow Controls a <tr> HTML element

Property Description

Align - Specifies the alignment of the table

Attributes - Returns all attributes name and value pairs of the element.

BGColor - Specifies the background color of the table

Border - Specifies the width of the borders

BorderColor - Specifies the color of the borders

Id - A unique id for the control

c. HtmlForm Controls a <form> HTML element

User can add only one form control for a web page

POST method is the default method of the Html form control

Property Description
Action - Contains a URL defining where to send the data in the form submitted

Attributes - Returns the attribute name and value pairs of the element

Name - Name of the form

Runat - Specifies that the control is a server control

Style - Set or return the CSS properties applied to the control

Visible - Specify a Boolean value whether the control should be visible or not

9.How to create a simple ASP.NET?application?Explain it with an example?


(APR-2016)

Creating an ASP.NET Application:

we can create an ASP.NET Web Application in one of the following ways:

 Using a text editor


 Using the Visual Studio.NET IDE

Creating an ASP.NET Application by Using a Text Editor:

Click Start Program Accessories Notepad to open the Notepad window.

Enter the following code in the notepad window

<html>

<head>

<title>My First ASP.NET Page</title>

<script runat=”server” language=”VB”>

Sub Page_Load(s As Object, e As EventArgs)

lblTime.Text=DateTime.Now.ToString()

End Sub

</script>

</head>

<body>

<p>Hello ther</p>

<p>The time is now: <asp:Label runat=”server”

id =”lb_Time”/></p>

</body>
</html>

Save the file by using the Save option from the File menu. Enter the name of the title as aspsample.aspx in
the Filename textbox of the save as dialog box.

To access spsample. Aspx Web application, you first need to set a virtual directory for the aspsample.aspx
file. To set a virtual directory on the windows 2000 Server component on which you have developed the
ASP.NET application, you need to perform the following steps.

Click Start Programs  Administrative ToolsInternet Services Manager to open the Internet
Information Services console.

Click the plus(+) sign next to the computer name to expand the web server tree.

Right-click the Default Web Site and select NewVirtual Directory option from the short-cut menu to open
the Virtual Directory Creation Wizard dialog box

Click the Next button to display the virtual directory alias page in the Virtual Directory Creation Wizard
dialog box. Specify the alias name as First in the Alias textbox.

Click the Next button to display the Web Site Content Director page in the Virtual Directory Creation
Wizard dialog box. Specify the directory path in which you have saved the First.aspx file in the Directory :
textbox.

Click the Next button to display the Access permissions page in the Virtual Directory Creation Wizard
dialog box. Ensure that Read and Run scripts permissions are selected in the Access permission page.

Click the Next button to display the last page of the Virtual Directory Creation Wizard dialog box. Click the
Finish button to close the Virtual Directory Creation Wizard dialog box.

After you create a virtual directory for an ASP.NET file, you can access the ASP.NET file by right-clicking
the file displayed in the right pane of the Internet Information Services and select the Browse option from
the short cut menu.

10. Describe the page structure of ASP.NET? (NOV. 2012, APR. 2012)

The important elements of an ASP.NET page are listed below

Directives

Code declaration blocks

ASP.NET controls

Code render blocks

Server-side comments

Server-side include directives

Literal text and HTML tags


Directives:-

A directive controls how the page is compiled. It is marked by the tags, <%@ and %>. It can appear
anywhere in a page. But, normally it is placed at the top of a page.

Syntax:

The general syntax for the directive statement is

<%@[Directive][Attribute=Value]%>

Code declaration blocks:-

Also called as script block

A code declaration block contains all the application logic for a page

It also includes declaration of global variables, and functions

It must be written within the <script runat=”server”> tag

Code declaration tags usually are placed in the <head> of your ASP.NET page

Code render blocks:-

Used to execute code within the HTML or text content of the ASP.NET page

Types:

Inline code:

Executes a statement or series of statements

Begins with the characters <% and ends with the characters%>

Inline expressions

Display the value of a variable or method

Begins with the characters <%= and end with the characters%>

ASP.NET Server Controls:

Server Controls represent the dynamic elements users interact with.

All controls must appear within a <form runat=”server”>tag

Have only one form per page in ASP.NET

<form id=”form1” runat=”server”>

<asp.Label ID=”Label1” runat=”server” Text=”Label”></asp:Label>

</form>
Server-side comments:-

Server-side comments will not be processed by ASP.NET

Used the <%-- beginning sequence and the --%> ending sequence

Advantage

Used to add documentation to a page

Example: <%-- This is a server-side comment --%>

Server-side include directives:- Used to include a file in an ASP.NET page

Two techniques:

Using the file attribute

Give the physical path to the file on the server either as an absolute path starting form the drive letter or a
relative path to the current file.

Using the virtual attribute

Specify the file’s location from the absolute root of the site or from a relative path to the current page.

Literal text and HTML tags:- Build the static part of an ASP.NET page using HTML tags and literal text.

11. What is DataGrid? State its purpose? (NOV. 2012)

DataGrid control to display data on the web page. It is used to display data in scrollable grid. It requires
data source to populate data in the grid.

Property Description

Id A unique id for the control

Runat Specifies that the control is a server control. Must be set to “server”

Example: Default.aspx

<html>

<head id=”head1” runat=”server”><title>Sample Web</title></head>

<body>

<form id=”form1” runat=”server”>

<asp:DataGrid ID=”DataGrid1” runat=”server”></asp:DataGrid>

</form>

</body></html>
Default.aspx.vb

Imports System.Data

Partial Class_Default

Inherits System.Web.UI.Page

Protected Sub Page_Load(By Val sender As Object, ByVal e As System.EventArgs) Handles


Me.Load

Dim table As DataTable=New DataTable(“Student”)

table.Columns.Add(“ID”)

table.Columns.Add(“Name”)

table.Columns.Add(“Email”)

table.Rows.Add(“101”,”Elakkiyaa”,[email protected])

table.Rows.Add(“102”,”Sanju”,[email protected])

DataGrid1.DataSource=table

DataGrid1.DataBind()

End Sub

End Class

12. Write a shorts notes on:ASP.NET Page Directive? (APR. 2016)

A page directive defines page-specific attributes like the language to be used

<%@Page Language=”VB”%>

The directive specifies instructions to the compiler. Two parameters are frequently used. This first is
Language, Language=VB. Here, it is set to VB, but it could be set to C# or any other .NET language. Next,
we set the Debug parameter to True,Debug=true.

The default for this parameter is False. If the parameter is set to True, the page will be compiled with debug
symbols. This means that when an error occurs on the page.

Another parameter you can set is Buffer: Buffer=false

The default is True. When the parameter is set to True, the response is buffered; that is, the response is held
until complete. If the property is set to False buffering does not occur.

Description=”This is my test page.”

The Description parameter is ignored by the compiler. The parameter can be set to any string you like, but it
typically is set to a description of the page.
Two compiler options you can set are Option Explicit and Option Strict:

Explicit=True

Strict=True

Option Explicit controls whether variable declaration is required.

Option Strict controls whether you allow variables to automatically be typed to different types as needed.

10 MARKS
1. Discuss the following in ASP.NET: (APR-2014)

(a)Radio Button List

(b)Check List Box

(a) Radio Button List:

The RadioButtonList control is used to create a group of radio button. Each selectable item in a
RadioButtonList control is defined by a ListItem element.

Property:

Property Description
Cell padding
The amount of pixels between the border and the contents of the
table cell

CellSpacing The amount of pixels between table cells

RepeatColumns The number of columns to use when displaying the radio button
group

RepeatDirection Specifies whether the radio button group should be repeated


horizontally or vertically

RepeatLayout The layout of the radio button group

Runat Specifies that the control is a server control. Must be set to “server”

TextAlign On which side of the radio button the text should appear

Example:

<asp:RadioButtionList id=”radio1” AutoPostBack=”True”

TextAlign=”Right” OnSelectedIndexChanged=”submit”

Runat=”sever”>
<asp:ListItem>C</asp:ListItem>

<asp:ListItem>C++</asp:ListItem>

<asp:ListItem>C#</asp:asp:ListItem>

</asp:RadioButtonList>

<asp:label id=”mess” runat=”server”/>

(b) CheckBoxList:-

The CheckBoxList control is used to create a multi-selection check box group. Each selectable item
in a CheckBoxList control is defined by a ListItem element.

Property:

Property Description

CellPadding The amount of pixels between the border and the contents of the
table cell

CellSpacing The amount of pixels between table cells

RepeatColumns The number of columns to use when displaying the radio button
group

RepeatDirection Specifies whether the check box group should be repeated


horizontally or vertically

RepeatLayout The layout of the check box group

Runat Specifies that the control is a server control. Must be set to “server”

TextAlign On which side of the check box the text should appear

Example:

<asp:CheckBoxList id=”radio1” AutoPostBack=”True”

TextAlign=”Right” OnSelectedIndexChanged=”submit” Runat=”sever”>

<asp:ListItem>C</asp:ListItem>

<asp:ListItem>C++</asp:ListItem>

<asp:ListItem>C#</asp:asp:ListItem>

</asp:CheckBoxList>

<asp:label id=”mess” runat=”server”/>


2.Describe on Drop down list and list box:- (NOV. 2015)

DropDownList:

The DropDownList control is used to create a drop-down list. Each selectable item in a DropDownList
control is defined by a ListItem element.

Property Description

SelectedIndex The index of a selected item

OnSelectedIndexChanged The name of the function to be executed when


the index of the selected item has changed

Runat Specifies that the control is a server control. Must


be set to “server”

Example:

<asp:DropDownList id=”radio1” AutoPostBack=”True” TextAlign=”Right”


OnSelectedIndexChanged=”submit” Runat=”sever”>

<asp:ListItem>C</asp:ListItem>

<asp:ListItem>C++</asp:ListItem>

<asp:ListItem>C#</asp:asp:ListItem>

</asp:DropDownList>

<asp:label id=”mess” runat=”server”/>

ListBox:

The ListBox control is used to create a single-or multi-selection drop-down list. Each selectable item
in a ListBox control is defined by a ListItem element.

Property:

Property Description

Rows The number of rows displayed in the list

SelectionMode Allows single or multiple selections

Example:

<asp:ListBox id=”radio1” AutoPostBack=”True” Rows=3 OnSelectedIndexChanged=”submit”


Runat=”sever”>

<asp:ListItem>C</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>

<asp:ListItem>C#</asp:asp:ListItem>

</asp:ListBox>

<asp:label id=”mess” runat=”server”/>

3. How web server controls are to be used in Asp.net? (NOV. 2012, APR. 2013, 2016)

Web Server controls are similar to HTML server controls. They are created on the server and builds
complex user interfaces with ease. All server controls must appear within a <form> tag, and the <form> tag
must contain the runat=”server” attribute.

Syntax:

<form runat=”server”>

<asp:control_name id=”some_id” runat=”server”/>

</form>

Label:

Label way to display static text on your page is simply to add the text to the body of the page without
enclosing it in any tag.

Example:

<asp:Label id=”lblMessage” Text=”Hello World” runat=”servere”/>

Text Box:

The TextBox control is used to create on screen a box in which the user can type or read standard text.
This web control can be set to display a standard HTML text input field, an HTML password field, or an
HTML text area, using the TextMode property.

Property Description

Text Returns/sets the text contained in the control.

TextMode Set the Text Mode property to the value


“Password/Multiline”

Columns Sets the size of the text box

Access Key Sets the key to use this control quickly

Tab Index Returns/sets the tab order of a control within the form

Rows Sets the number of lines to be entered in the control.

Example:
<p>Username:

<asp: TextBox id=”txtUser” TextMode=”SingleLine” Columns=”30” runat=”server”/></p>

Button:

The Button control renders the same form submit button that’s rendered by the HTML <input
type=”Submit”> tag. When a button is clicked, the form containing the button is submitted to the
server for processing, and both click and command events are raised.

Example:

<asp:Button id=”btr.Submit” Text=”Submit” runat=”server” OnClick=”writeText”/>

Image:

An Image control places on the page an image that can be accessed dynamically from code; it
equates to the <img> tag in HTML.

Example:

<asp:Image id=”myImage” ImageUrl=”mygif.gif” runat=”server” AlternateText=”description”/>

ImageButton:

An Image Button control is similar to a Button control, but it uses an image you supply in
place of the typical gray Windows-style button.

Property Description

Image URL Set the path of the location

Image Align Sets the alignment of the image

Alternate Text Sets the text displayed when the mouse is paused
over the image

Example:

<asp:Image id=”myImgButton” ImageUrl=”myButton.gif” runat=”server”/>

LinkButton:

A Link Button control renders a hyperlink on your page. From the point of view of
ASP.NET code Link Buttons can be treated in much the same way as buttons, hence the
name.

Example:

<asp:LinkButton id=”myLinkButton” Text=”Click Here” runat=”server”/>


HyperLink:

The Hyperlink control, which is similar to the Link Button control, creats a hyperlink on your page.

HyperLink Control:

Properties Description

Target Indicates the named frame for the HREF hyperlink


to jump to. Set to the name of a frame.

Navigate URL Sets the location to navigate

Example:

<asp:HyperLink id=”my Link”NavigateUrl=http://www.example.com/ ImageUrl=”myButton.gif”


runat=”server”>MyLink</asp:HyperLink>

RadioButton:

We can add individual radio buttons to the page one by one, using the RadioButton control. Radio
Buttons are grouped together using the GroupName property. Only one Radiobutton control from
each group can be selected at a time.

Example:

<asp:RadioButton id =”radBsc” GroupName=”Courses” Text=”Bsc” runat=”server”/>

CheckBox:

we can use of CheckBox control to represent a choice that can be only a yes (checked) or no
(unchecked) value.

Example:

<asp: CheckBox id=”chkQuestion” Text=”I like .NET!” runat=”server”/>

4. Explain about OLEDB connection class and page directive? (APR. 2016)

OLEDB connection class represents an open connection to a data source.

Constructors:

Constructors Description

OleDbConnection() Initializes a new instance of the OleDbConnection


class.

OleDbConnection(String) Initializes a new instance of the OleDbConnection


class with the specified connection string
Property Description

ConnectionString Gets or Sets the string used to open a database

ConnectionTimeout Gets the time to wait while trying to establish a connection


before terminating the attempt and generating an error.

DataSource Gets the server name or file name of the data source

Provider Gets the name of the OLEDB provider specified in the


“Provider=” clause of the connection string

Methods:

Methods Description

Open() Opens a database connection with the property


settings specified by the ConnectionString

Close() Closes the connection to the data source

ToString() Returns a String containing the name of the


Component,

Equals(Object) Determines whether the special object is equal to the


current object

Example:

OleDbConnection con=new OledbConnection(“Provider=Microsoft.Jet.OLEDB.4.0; Data


Source=F:/C#/Academic.mdb”);

Page Directive. REFER Q.NO:5 (In 5 Marks)

UNIT – V
2 MARKS
1. How an IP address is provided.(NOV.2014,APR.2014)
Addresses which are provided dynamically, are done so from a server on the network called a "DHCP"
(Dynamic Host Configuration Protocol) Server. The server is configured with a database that contains all of
the IP addresses available for use on the network
2. Give the expansion of SSL(APR.2013)
 Secure Sockets Layer(SSL) is the standard security technology for establishing an encrypted link
between a web server and a browser.
 This link ensures that all data passed between the web server and browsers remain private and integral.
 SSL is an industry standard and is used by millions of websites in the protection of their online
transactions with their customers
3. Define Authentication(APR.2014,NOV.2013)
 Authentication is the process of validating the identity of a user to allow or deny a request.
 This involves accepting the credentials (eg.user name and password) from the users and validating it
against a designated authority.
4. What is the difference between node and host
Host:
 For companies or individuals with a Web site, a host is a computer with a Web server that serves the
pages for one or more Web sites.
 A host can also be the company that provides that service, which is known as hosting.
Node:
 In a network, a node is a connection point, either a redistribution point or an end point for data
transmissions.
 In general, a node has programmed or engineered capability to recognize and process or forward
transmissions to other nodes.
5. What is the purpose of routers
 The main purpose of a router is to connect multiple networks and forward packets destined either for its own
networks or other networks.
 A router is considered a layer-3 device because its primary forwarding decision is based on the information
in the layer-3 IP packet, specifically the destination IP address
6. Define protocol
 A protocol defines rules and conventions for communication between network devices.
 Protocols include mechanisms for devices to identify and make connections with each other, as well as
formatting rules that specify how data is packaged into messages sent and received
7. What is the role of server.(APR.2015)
 A server role is a set of software programs that, when they are installed and properly configured, lets a
computer perform a specific function for multiple users or other computers within a network.
 Generally, roles share the following characteristics. They describe the primary function, purpose, or use
of a computer.
8. Define MIME.(APR.2015)
MIME (Multi-Purpose Internet Mail Extensions) is an extension of the original Internet e-
mail protocol that lets people use the protocol to exchange different kinds of data files on the Internet: audio,
video, images, application programs, and other kinds
9. What are servlets.(APR.2015)
 A servlet is simply a class which responds to a particular type of network request -
most commonly an HTTP request.
 Basically servlets are usually used to implement web applications - but there are also
various frameworks which operate on top of servlets (e.g. Struts) to give a higher-
level abstraction than the "here's an HTTP request, write to this HTTP response" level
which servlets provide.

11. What do you mean by server-side.(APR. 2015)


 The server-side environment that runs a scripting language is a web server.
 A user's request is fulfilled by running a script directly on the web server to generate dynamic HTML
pages.
 This HTML is then sent to the client browser.
 It is usually used to provide interactive web sites that interface to databases or other data stores on the
server
12. Define Dataset classes.(APR.2016)
 The Dataset class is a base class that offers a number of functions common to all types of metadata
datasets.
 There is a separate inheriting class for each metadata data model supported by the scripting API: XML
data model, JDF data model, XMP data model, and Opaque data model.
13. Write a note on Client certificate.(APR. 2016)
 A client authentication certificate is a certificate used to authenticate clients during an SSL handshake.
 It authenticates users who access a server by exchanging the client authentication certificate
14. Give the expansion of OLEDB.(NOV.2013)
OLEDB stands for Object Linking and Embedding for Database
15. Define port
 In programming, a port is a logical connection place and specifically, using the Internet's protocol,
TCP/IP, the way a client program specifies a particular server program on a computer in a network.
 Higher-level applications that use TCP/IP such as the Web protocol, Hypertext Transfer Protocol, have
ports with pre-assigned numbers.
16. What are the functions of a browser
 The primary function of a web browser is to render HTML, the code used to design or markup
webpages.
 Each time a browser loads a web page, it processes the HTML, which may include text, links, and
references to images and other items, such as cascading style sheets and JavaScript functions.
 The browser processes these items, then renders them in the browser window
17. What is a scriptlet?
 A scriptlet is a piece of software code that is used by a native Web page scripting language to perform a
specific function or process.
 Scriptlets are primarily implemented in JavaServer Pages (JSP) and include variables, expressions or
statements that are used only when requested by a certain client or process.
18. Define URL Encoding
 URL Encoding is the process of converting string into valid URL format.
 It is also known as Percent-encoding, which is a mechanism for encoding information in a Uniform
Resource Identifier (URI) under certain circumstances
19. List the predefined MIME concept types.(NOV.2015)
Two primary MIME types are important for the role of default types:
 text/plain - is the default value for textual files. A textual file should be human-readable and must not
contain binary data.
 application/octet-stream - is the default value for all other cases. An unknown file type should use this
type. Browsers pay a particular care when manipulating these files, attempting to safeguard the user to
prevent dangerous behaviors.
20. How data set can be used in .NET.(APR.2012)
 We can use Fill method of the DataAdapter for populating data in a Dataset.
 The DataSet can be filled either from a data source or dynamically.
21. State the difference between request cookies and response cookies.(JULY 14)
 Request Cookies are the cookies sent along with the request (i.e.,) from browser to server.
 Response Cookies are the cookies get get sent out (i.e.,) from server to browser.

5 MARKS
1.What is meant by authentication? Explain.(APR.2014)
It is the process of ensuring the user’s identity and authenticity. ASP.NET allows four types of authentications:
 Windows Authentication
 Forms Authentication
 Passport Authentication
 Custom Authentication
1. WINDOWS AUTHENTICATION
If your application is targeted for use inside an organization, and users accessing the application have
existing user accounts within the local user database of the Web server or Active Directory, you should
authenticate users with Windows authentication.
2. FORMS AUTHENTICATION
By default, Form authentication is used. Form-based authentication presents the user with an
HTML-based Web page that prompts the user for credentials.
3. PASSPORT AUTHENTICATION
You can also authenticate users using a service from Microsoft called Passport. Passport is a
centralized directory of user information that Web sites can use, in exchange for a fee, to authenticate users.
Users can choose to allow the Web site access to personal information stored on Passport, such as the users'
addresses, ages, and interests.
4. CUSTOM AUTHENTICATION
When standard types of authentication do not meet your requirements, you need to modify an
authentication mechanism to create a custom solution. A user context has principal which represents the
identity and roles for that user. A user is authenticated by its identity and assigned roles to a user determine
about authorization or permission to access resources.

2. Explain the functions of browser object?


The Browser object of a request object returns an HttpBrowserCapabilities object. This object has the
properties that tells you things about the visitor’s browser. For example, you can reference a property of the
object to determine the operating system in use by the visitor,

x = BCaps.Platform
This type of information is helpful because you may define more than one version of a Website. Each
version would be specialized so that it looked best for the specific browser that the visitor was using.
The BC.aspx ASP.NET page demonstrates the use of many of the properties of object. In code, the
values of the visitor’s browser are placed into a Label control .
Within the body of the page, the Label control is defined
<asp:Label
Id=”lblMessage1”
runat=”Server”
Font-Bold=”True”
/>

3. Explain the concept of error handling. (APR.2013)


When errors occur in an ASP.NET application, they either get handled or propagates unhandled to
higher scopes. When an unhandled exception propagates, the user may be redirected to an error page using
different ASP.NET configuration settings. However, such a redirection may be prevented in the first place by
handling the exceptions that get thrown. Error handling in ASP.NET therefore, may be divided into two
separate logics:
1. Redirecting the user to an error page when errors go unhandled.
2. Handling exceptions when they get thrown.
1. Redirecting the user to an error page:-
There are two different scopes where we could specify which page the user should be redirected to, when
errors go unhandled:
 Page level (applies to errors that happen within a single page).
 Application level (applies to errors that happen anywhere in the application).
Page Level:-
 Use the errorPage attribute in the webform.
 This attribute defines the page the user should be redirected to when an unhandled exception occurs
in that specific page. For example,
<%@Page language="c#"Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="WebTest.WebForm1"

errorPage="/WebTest/ErrorPages/PageError.html"%>

The errorPage attribute maps to the Page.ErrorPage property, and hence may be set
programmatically. The value may optionally include query string parameters. If no parameters are added,
ASP.NET would automatically add one with the name aspxerrorpath. This parameter would hold the value
of the relative URL to this page, so that the error page would be able to determine which page caused the
error.
If a value is specified in this attribute (or property) and an unhandled exception occurs in the page,
the Pageclass would automatically perform a redirect to the specified page. If a value is not specified, the
exception is assumed to be unhandled, wrapped in a new HttpUnhandledException and then thrown,
propagating it to the next higher level.
Application Level:-
 Use the customErrors section in web.config.
 This section lets you specify the error page to which the user should be redirected to when an
unhandled exception propagates in the application level. This section specifies error pages for both
default errors as well as the HTTP status code errors.
<customErrors mode="On"
defaultRedirect="/WebTest/ErrorPages/AppError.html">

<error statusCode="404" redirect="/WebTest/ErrorPages/404.html"/>

</customErrors>

The mode attribute specifies whether to show user-defined custom error pages or ASP.NET error
pages. Three values are supported for this attribute:
RemoteOnly - Custom error pages are shown for all remote users. ASP.NET error pages with rich error
information are displayed only for local users.
On - Custom error pages are always shown, unless one is not specified. When a custom error page is not
defined, an ASP.NET error page will be displayed which describes how to enable remote viewing of errors.
Off - Custom error pages are not shown. Instead, ASP.NET error pages will be displayed always, which will
have rich error information.
4. Write about IP address and authentication.(APR.2015)
(a). IP Address:-
 An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer,
printer) participating in a computer network that uses the Internet Protocol for communication.
 An IP address serves two principal functions: host or network interface identification and location
addressing.
 Its role has been characterized as follows: "A name indicates what we seek. An address indicates where
it is. A route indicates how to get there.”
 There are two versions of IP address, earlier Version of IP address is IPv4 contains IP address as 32 bit
number, and then because of growth of internet new version of IP is developed named IPv6 which takes
128 bit to store the IP Address.
(b). Authentication:-
It is the process of ensuring the user’s identity and authenticity. ASP.NET allows four types of
authentications:
 Windows Authentication
 Forms Authentication
 Passport Authentication
 Custom Authentication
1. WINDOWS AUTHENTICATION
If your application is targeted for use inside an organization, and users accessing the application have
existing user accounts within the local user database of the Web server or Active Directory, you should
authenticate users with Windows authentication.
2. FORMS AUTHENTICATION
By default, Form authentication is used. Form-based authentication presents the user with an
HTML-based Web page that prompts the user for credentials.
3. PASSPORT AUTHENTICATION
You can also authenticate users using a service from Microsoft called Passport. Passport is a
centralized directory of user information that Web sites can use, in exchange for a fee, to authenticate users.
Users can choose to allow the Web site access to personal information stored on Passport, such as the users'
addresses, ages, and interests.
4. CUSTOM AUTHENTICATION
When standard types of authentication do not meet your requirements, you need to modify an
authentication mechanism to create a custom solution. A user context has principal which represents the
identity and roles for that user. A user is authenticated by its identity and assigned roles to a user determine
about authorization or permission to access resources.
5. Describe about working with IIS
IIS Authentication:-
The Secure Socket Layer or SSL is the protocol used to ensure a secure connection. With SSL enabled,
the browser encrypts all data sent to the server and decrypts all data coming from the server. At the same time,
the server encrypts and decrypts all data to and from browser.
The URL for a secure connection starts with HTTPS instead of HTTP. A small lock is displayed by a
browser using a secure connection. When a browser makes an initial attempt to communicate with a server over
a secure connection using SSL, the server authenticates itself by sending its digital certificate.
To use the SSL, you need to buy a digital secure certificate from a trusted Certification Authority (CA)
and install it in the web server.
SSL is built into all major browsers and servers. To enable SSL, you need to install the digital
certificate. The strength of various digital certificates varies depending upon the length of the key generated
during encryption. More the length, more secure is the certificate, hence the connection.
Strength Description
40 bit Supported by most browsers but easy to break.
56 bit Stronger than 40-bit.
128 bit Extremely difficult to break but all the browsers do not
support it.

6.What is E-mail? Discuss briefly.(NOV.2013,NOV.2014)


 E-mail (electronic mail) is the exchange of computer-stored messages by telecommunication.
 E-mail messages are usually encoded in ASCII text. However, you can also send non-text files, such as
graphic images and sound files, as attachments sent in binary streams.
 E-mail was one of the first uses of the Internet and is still the most popular use. A large percentage of
the total traffic over the Internet is e-mail.
 E-mail can also be exchanged between online service provider users and in networks other than the
Internet, both public and private.
 E-mail can be distributed to lists of people as well as to individuals.
 A shared distribution list can be managed by using an e-mail reflector.
 Some mailing lists allow you to subscribe by sending a request to the mailing list administrator.
 A mailing list that is administered automatically is called a list server.
 E-mail is one of the protocols included with the Transport Control Protocol/Internet Protocol (TCP/IP)
suite of protocols.
 A popular protocol for sending e-mail is Simple Mail Transfer Protocol and a popular protocol for
receiving it is POP3.
 Both Netscape and Microsoft include an e-mail utility with their Web browsers

7.Write short notes on : IP address and client certificates.(NOV.2015)


(a). IP Address:-
 An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer,
printer) participating in a computer network that uses the Internet Protocol for communication.
 An IP address serves two principal functions: host or network interface identification and location
addressing.
 Its role has been characterized as follows: "A name indicates what we seek. An address indicates where
it is. A route indicates how to get there.”
 There are two versions of IP address, earlier Version of IP address is IPv4 contains IP address as 32 bit
number, and then because of growth of internet new version of IP is developed named IPv6 which takes
128 bit to store the IP Address.
(b). Client Certification:-
SSL uses digital certificates to authenticate servers. (SSL also includes an optional authentication for
clients). Certificates are digital documents that will attest to the binding of a public key to an individual or other
entity. They allow verification of the aim that a specific public key does, in fact, belong to the specified entity.
Certificates help prevent someone from impersonating the server with a false key. SSL uses X.509 certificates
to validate identities.
X.509 certificates contain information about the entity including public key and name. A certificate
authority then validates this certificate.

8.Explain the various security attacks in network


 There are some basic class of attacks which can be a cause for slow network performance, uncontrolled
traffic, viruses etc.
 Attacks to network from malicious nodes.
 Attacks can be categories in two:
1. "Passive" when a network intruder intercepts data traveling through the network
2. "Active" in which an intruder initiates commands to disrupt the network's normal operation
1. ACTIVE ATTACKS:-
a. Spoofing:-
When a malicious node miss-present his identity, so that the sender change the topology
b. Modification :-
When malicious node performs some modification in the routing route, so that sender sends the
message through the long route. This attack cause communication delay occurred between sender and
receiver.
c. Wormhole:-
This attack is also called the tunnelling attack. In this attack an attacker receives a packet at one
point and tunnels it to another malicious node in the network. So that a beginner assumes that he found
the shortest path in the network
d. Fabrication:-
A malicious node generates the false routing message. This means it generate the incorrect
information about the route between devices
e. Denial of services:-
In denial of services attack, malicious node sending the message to the node and consume the
bandwidth of the network. The main aim of the malicious node is to be busy the network node. If a
message from unauthenticated node will come, then receiver will not receive that message because he is
busy and beginner has to wait for the receiver response.
f. Sinkhole:-
Sinkhole is a service attack that prevents the base station from obtaining complete and correct
information. In this attack, a node tries to attract the data to it from his all neighbouring node. Selective
modification, forwarding or dropping of data can be done by using this attack
g. Sybil:-
This attack related to the multiple copies of malicious nodes. The Sybil attack can be happen due
to malicious node shares its secret key with other malicious nodes. In this way the number of malicious
node is increased in the network and the probability of the attack is also increases. If we used the
multipath routing, then the possibility of selecting a path malicious node will be increased in the
network
2. PASSIVE ATTACKS:-
a. Traffic analysis:-
In the traffic analysis attack, an attacker tries to sense the communication path between the
sender and receiver. An attacker can found the amount of data which is travel from the route of sender
and receiver. There is no modification in data by the traffic analysis.
b. Eavesdropping:-
This is a passive attack, which occurred in the mobile ad-hoc network. The main aim of this
attack is to find out some secret or confidential information from communication. This secrete
information may be privet or public key of sender or receiver or any secrete data.
c. Monitoring:-
In this attack in which attacker can read the confidential data, but he cannot edit the data or
cannot modify the data.
9. Discuss the input elements in the request.Form collection.(NOV.2014)
The QueryString collection allows you to access the values of parameters passed into the page through
the URL or the link to the page; but another collection required to retrieve the values of parameters that were
passed into the page through Form controls, such as HTML Select elements and HTML Textbox elements on
the page. You retrieve those values through the Form collection of the Request object.
Suppose you defined an HTML Textbox form element like this one on a page:
<input name=”MyField” type=”text” value= “ ” />
The ASP.NET page that is posted to when the visitor clicks the submit button on the page could access the
value of the field like this:
Request.Form(“MyField”)

10. Where are cookies actually stored on the hard disk? Explain
A cookie is a piece of text that a web server can store on a user's hard disk. Cookies allow a Web site to
store information on a user's machine and later retrieve it. The pieces of information are stored as name-value
pairs.
For example, a Web site might generate a unique ID number for each visitor and store the ID number on
each user's machine using a cookie file.
If you use Microsoft's Internet Explorer to browse the Web, you can see all of the cookies that are stored
on your machine. The most common place for them to reside is in a directory called c:windowscookies. When I
look in that directory on my machine, I find 165 files. Each file is a text file that contains name-value pairs, and
there is one file for each Web site that has placed cookies on my machine.
You can see in the directory that each of these files is a simple, normal text file. You can see which Web
site placed the file on your machine by looking at the file name (the information is also stored inside the file).
You can open each file by clicking on it.
For example, I have visited goto.com, and the site has placed a cookie on my machine. The cookie file
for goto.com contains the following information:
UserID A9A3BECE0563982D www.goto.com/
Goto.com has stored on my machine a single name-value pair. The name of the pair is UserID, and the
value is A9A3BECE0563982D. The first time I visited goto.com, the site assigned me a unique ID value and
stored it on my machine.
(Note that there probably are several other values stored in the file after the three shown above. That is
housekeeping information for the browser.)

11. What is the difference between Logic controls and Form Authentication
 Forms authentication can be easily implemented using login controls without writing any code.
 Login control performs functions like prompting for user credentials, validating them and issuing
authentication just as the FormsAuthentication class.
 However, all that’s needs to be done is to drag and drop the use control from the tool box to have these
checks performed implicitly.
 The FormsAuthentication class is used in the background for the authentication ticket and ASP.NET
membership is used to validate the user credentials.

12. What is response object? How it is related to ASP's response object. (JULY 2012)
RESPONSE OBJECT:-
 The Response object is used to send output to the client from the web server.
 It is an instance of the System.Web.HttpResponse class.
 In ASP.NET, the response object does not play any vital role in sending HTML text to the client,
because the server-side controls have nested, object oriented methods for rendering themselves.
Syntax:-
Response.collection|property|method
Collections:-
Collection Description
Cookies The Cookies collection sets the value of a cookie. If you attempt to set the value of a cookie that
does not exist, it is created. If it already exists, the new value you set overwrites the old value
already written to the client machine.

Properties:-
Property Description
Buffer The Buffer property determines whether to buffer page output or not. If set to True,
then output from the page is not sent to the client until the script on that page has been
processed, or until the Response object Flush or End methods are called.

CacheControl The CacheControl property determines whether proxy servers are able to cache the output
generated by ASP or not. If your page’s content is large and doesn’t change often, you
might want to allow proxy servers to cache the page. In this case set this property to
Public. Otherwise set it to Private.

Charset The Charset property appends the name of the character set to the Content-Type header in
the Response object.
ContentType The ContentType property specifies the HTTP content type for the response. If not
specified, the default is "text/html".

Expires The Expires property specifies the length of time (in minutes) that the client machine will
cache the current page. If the user returns to the page before it expires, the cached version
will be displayed.

ExpiresAbsolute The ExpiresAbsolute property specifies a date and time on which a page cached on a
browser will expire. If the user returns to the same page before that date and time, the user
will view the cached version of the page. If no time is specified, the page expires at
midnight on the date specified. If a date is not specified, the page expires at the given time
on the day that the script is run.

IsClientConnected The IsClientConnected property is a read-only property that indicates if the client has
disconnected from the web server since the last use of the Response object’s Write
method.

Pics The PICS (Platform for Internet Content Selection) property adds a value to the pics-label
field of the response header.

Status The Status property specifies the value of the status line that is returned to the client
machine from the web server.

Methods:-
Method Description
AddHeader The AddHeader method allows you to add your own HTTP header with a specified
value. If you add an HTTP header with the same name as a previously added header,
the second header will be sent in addition to the first; adding the second header does not
overwrite the value of the first header with the same name. Also, once the header has
been added to the HTTP response, it cannot be removed.

AppendToLog The AppendToLog method adds a string to the end of the Web server log entry for the
current page request. You can only add up to 80 characters at a time, but you can call
this method multiple times.

BinaryWrite The BinaryWrite method writes information directly to the output without any character
conversion.

Clear The Clear method erases any buffered HTML output. It does so without sending any of
the buffered response to the client. Calling Clear will cause an error if Buffer property
of the Response object is not set to True.

End The End method stops the processing of the script in the current page and sends the
already created content to the client. Any code present after the call to the End method
is not processed.
Flush The Flush method sends buffered output to the client immediately. Flush will cause a
run-time error if Buffer property of the Response object is not set to True.

Redirect The Redirect method redirects the user to a different URL.

Write The Write method writes a specified string to the output

10 MARKS
1. How security can be provided by SSL and client certificates? Explain.(APR.2014, JULY 2014)
SSL BASICS:-
 Secure Sockets Layer(SSL) is the standard security technology for establishing an encrypted link
between a web server and a browser.
 This link ensures that all data passed between the web server and browsers remain private and integral.
 SSL is an industry standard and is used by millions of websites in the protection of their online
transactions with their customers
SSL Element:-
The main role of SSL is to provide security for Web traffic. Security includes confidentiality, message
integrity, and authentication.
SSL achieves these elements of security through the use of
 Cryptography
 Digital Signatures
 Certificates
1. Cryptography:-
SSL protects confidential information through the use of cryptography. Sensitive data is encrypted
across public networks to achieve a level of confidentiality.
There are two types of data encryption:
 Symmetric cyrptography
 Asymmetric cryptography
(i)Symmetric Cryptography:-
 Symmetric cryptography uses a single key for encryption and decryption.
 Symmetric cryptography requires that both parties have the key.
 Key distribution is the inherent weakness in symmetric cryptography
 Minimal CPU cycles are required to verify keys
 Symmetric ciphers are fortified by algorithmic strength and key lengths.
 SSL symmetric key lengths range from 40 to 168 bits.
(ii)Asymmetric Cryptography:-
 Asymmetric cryptography was designed in response to the limitations of symmetric
cryptography
 Information encrypted with one key can be decrypted only with another key
 Public key infrastructure (PKI) cryptography is up to 1000 times more than CPU intensive than
symmetric cryptography
 The Rivest,Shamir,Adelman(RSA) algorithm uses modular arithmetic to enable the concept of
public and private keys
 All SSL transactions begin with an asymmetric key exchange.

CLIENT CERTIFICATION:-
SSL uses digital certificates to authenticate servers. (SSL also includes an optional authentication for
clients). Certificates are digital documents that will attest to the binding of a public key to an individual or other
entity. They allow verification of the aim that a specific public key does, in fact, belong to the specified entity.
Certificates help prevent someone from impersonating the server with a false key. SSL uses X.509 certificates
to validate identities.
X.509 certificates contain information about the entity including public key and name. A certificate
authority then validates this certificate.

2. Explain the technique of working with IIS and page directives.(APR.2013)


IIS AUTHENTICATION:-
The Secure Socket Layer or SSL is the protocol used to ensure a secure connection. With SSL enabled,
the browser encrypts all data sent to the server and decrypts all data coming from the server. At the same time,
the server encrypts and decrypts all data to and from browser.
The URL for a secure connection starts with HTTPS instead of HTTP. A small lock is displayed by a
browser using a secure connection. When a browser makes an initial attempt to communicate with a server over
a secure connection using SSL, the server authenticates itself by sending its digital certificate.
To use the SSL, you need to buy a digital secure certificate from a trusted Certification Authority (CA)
and install it in the web server.
SSL is built into all major browsers and servers. To enable SSL, you need to install the digital
certificate. The strength of various digital certificates varies depending upon the length of the key generated
during encryption. More the length, more secure is the certificate, hence the connection.
Strength Description
40 bit Supported by most browsers but easy to break.
56 bit Stronger than 40-bit.
128 bit Extremely difficult to break but all the
browsers do not support it.

PAGE DIRECTIVES:-
The page directives set up the environment for the page to run. The @Page directive defines page-
specific attributes used by ASP.NET page parser and compiler. Page directives specify how the page should be
processed, and which assumptions need to be taken about the page. It allows importing namespaces, loading
assemblies, and registering new controls with custom tag names and namespace prefixes.
The Page directive defines the attributes specific to the page file for the page parser and the compiler.
The basic syntax of Page directive is:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Trace="true" %>

Some of the attributes of the Page directive are:


Attributes Description
1.AutoEventWireup The Boolean value that enables or disables
page events that are being automatically bound
to methods; for example, Page_Load.
Buffer The Boolean value that enables or
disables HTTP response buffering.
2.ClassName The class name for the page.
3.ClientTarget The browser for which the server controls
should render content.
4.CodeFile The name of the code behind file.
5.Description The text description of the page, ignored by the
parser.
6.EnableSessionState It enables, disables, or makes session state
read-only.
7.Language The programming language for code.

3. Explain about OLEDB Connection Class.(APR.2015,APR.2016)


The OLEDBConnection Object provides the means to connect to a database. This is done through a
connection string. Typically, you will declare an object of a class like this:
Dim MyConnection as OleDbConnection

Later in code, when you get to the point at which you need to connect to the database, you will
instantiate the object and supply the object with the connect string in that statement:
MyConnection = New
OleDbConnection(“PROVIDER=” _

& ”ProvidenName;” _

& ”DATA SOURCE=” _

& ”DataSourceName;” _
A connect string & ”Other Parameter=” _ is made up of parameters
that are needed to connect to the database
successfully. Each of the & ”OtherParameterValue” _) parameters contains the
name of the parameter followed by its value
preceded by an equal sign. Each parameter in the connect string is separated by a semicolon.

Connect string vary depending on the type of the database you are connecting to, but, typically, they
contain the name of the provider, which is the library to use to connect to the database, and some path or name
for the database. Often you will find parameters such as user names and passwords that are associated with a
database in a connect string.
A connect string to an Access database frequently look like this:
MyConnection = New OleDbConnection(“PROVIDER=”
_

& “Microsoft.Jet.OLEDB.4.0;” _

& “DATA SOURCE=” _

& “c:\SomeFolder\DBName.mdb”)

 The first parameter states the name of the provider to use to connect to the Access database
 The second parameter specifies the full path to the database to open.

Once you have supplied a connect string, you connect to the database by calling the Open method:
MyConnection.Open()

When you have finished with a database connection, you disconnect from the database by calling the
Close method:
MyConnection.Close()

4. Explain the importance of client certificates in providing security.(NOV.2013)


CLIENT CERTIFICATION:-
SSL uses digital certificates to authenticate servers. (SSL also includes an optional authentication for
clients). Certificates are digital documents that will attest to the binding of a public key to an individual or other
entity. They allow verification of the aim that a specific public key does, in fact, belong to the specified entity.
Certificates help prevent someone from impersonating the server with a false key. SSL uses X.509 certificates
to validate identities.
X.509 Certificates:-
As an alternative to authenticating with a user ID and passwords, users can present X.509 client
certificates for accessing Web applications. In this case, user authentication takes place using the underlying
Secure Sockets Layer (SSL) protocol and users do not need to interactively enter a password for logon.
For an overview of the authentication process flow when using X.509 certificates, see the figure below.
X.509 Certificate Authentication Flow
Authentication with X.509 Certificates makes use of a Public Key Infrastructure (PKI) to securely
authenticate users. After users receive their X.509 certificates from a certificate issuing Certification Authority
(CA), they can use them to securely access SAP NetWeaver, as well as non-SAP systems. The SAP
NetWeaver and the non-SAP system can authorize access requests, based on an established trust relationship
with the CA.
In addition, users can use their X.509 certificates to authenticate their access to systems located on the
Internet and within your company Intranet. Thereby, you can use certificates for authentication in open
environments such as the Internet.
Prerequisites
 You have deployed a public key infrastructure to support issuing public key certificates to users.
 To use certificates for authentication with AS ABAP, the AS ABAP must be release 4.5B or higher.
Security Considerations:-
X.509 certificates use industry standard cryptographic mechanisms to securely authenticate user access.
The exchange of the authentication credentials between the front-end Web client and the AS ABAP, AS Java or
non-SAP system is secured through the use of public key cryptography and the underlying SSL protocol. For
additional security, you can also enable mutual authentication, where both the front-end client and the back-end
application server exchange X.509 certificates to mutually establish their identities.
When using X.509 client certificates and SSL for user authentication, you should note the following:
 Your users need to possess valid certificates signed by a trusted CA. You can either establish your own
CA and distribute certificates to your users yourself, or you can rely on a Trust Center service. The CA
you choose to use must be designated as a trusted CA on the accepting SAP NetWeaver system.
 Users should be informed about how to protect their private key.

When using authentication with client certificates, each user needs to possess a key pair, consisting of a
public and a private key. The public key is contained in the X.509 client certificate and can be made public.
However, the user's private key needs to be kept safe.
The possibilities available for securing the private key depend on the Web browser that you use. (For
example, you may be able to protect it with a password or you may be able to use smart cards.) If the private
key is stored on the front-end client, your users should use screensavers protected with a password.
 If users share Web browsers for clients, then note the following:
As long as the operating system separates and protects user data at the operating system level (for example,
Windows NT), then the private key stored on the Web front-end client is protected by the operating system.

5. Explain about Request and Response objects.(NOV20, 15)


REQUEST OBJECT:-
 The Request object retrieves the values that the client browser passed to the server during an HTTP
request.
 It is used to get information from the user.
 Using this object, you can dynamically create web pages and perform various server-side actions based
on input from the user.
 The syntax, collections, properties and methods of the ASP Request object are as follows:

Syntax:-
Request[.collection|property|method](variable)
Collections:-
Collection Description
ClientCertificate The ClientCertificate collection provides access to the
certification fields from a request issued by the web
browser. Commonly, it is used when the client is requesting
secure pages through SSL connection. Before using this
collection, you must configure your Web server to request
client certificates.
Cookies The Cookies collection allows you to retrieve the values of
the cookies sent in an HTTP request.
Form The Form collection allows you to retrieve the data input
into an HTML form posted to the HTTP request body by a
form using the POST method.
QueryString The QueryString collection allows you to retrieve the values
of the variables in the HTTP query string. For example, it
parses the values sent by a form using the GET Method. The
QueryString collection is less capable than the Form
collection, since there is a limit to the amount of data that
can be sent in the header of an HTTP request.
ServerVariables The ServerVariables collection contains the values of
predefined environment variables plus all of the HTTP
header values sent from the client browser to the web server.
Properties:-
Property Description
TotalBytes The TotalBytes property is a read-only
property that specifies the total number of
bytes sent by the client in the HTTP request
body. It is important when preparing to read
data from the request body using the
BinaryRead method of the Request object.

Methods:-
Method Description
BinaryRead The BinaryRead method retrieves the data sent to the
server from the client as part of a POST request and stores
it in a SafeArray. A SafeArray is a special variant array
that contains, in addition to its items, the number of
dimensions in the array and the upper bounds of the array.

RESPONSE OBJECT:-
 The Response object is used to send output to the client from the web server.
 It is an instance of the System.Web.HttpResponse class.
 In ASP.NET, the response object does not play any vital role in sending HTML text to the client,
because the server-side controls have nested, object oriented methods for rendering themselves.
Syntax:-
Response.collection|property|method
Collections:-
Collection Description
Cookies The Cookies collection sets the value of a cookie. If you attempt to set the value of a cookie that
does not exist, it is created. If it already exists, the new value you set overwrites the old value
already written to the client machine.

Properties:-
Property Description
Buffer The Buffer property determines whether to buffer page output or not. If set to True,
then output from the page is not sent to the client until the script on that page has been
processed, or until the Response object Flush or End methods are called.

CacheControl The CacheControl property determines whether proxy servers are able to cache the output
generated by ASP or not. If your page’s content is large and doesn’t change often, you
might want to allow proxy servers to cache the page. In this case set this property to
Public. Otherwise set it to Private.

Charset The Charset property appends the name of the character set to the Content-Type header in
the Response object.

ContentType The ContentType property specifies the HTTP content type for the response. If not
specified, the default is "text/html".

Expires The Expires property specifies the length of time (in minutes) that the client machine will
cache the current page. If the user returns to the page before it expires, the cached version
will be displayed.

ExpiresAbsolute The ExpiresAbsolute property specifies a date and time on which a page cached on a
browser will expire. If the user returns to the same page before that date and time, the user
will view the cached version of the page. If no time is specified, the page expires at
midnight on the date specified. If a date is not specified, the page expires at the given time
on the day that the script is run.

IsClientConnected The IsClientConnected property is a read-only property that indicates if the client has
disconnected from the web server since the last use of the Response object’s Write
method.

Pics The PICS (Platform for Internet Content Selection) property adds a value to the pics-label
field of the response header.

Status The Status property specifies the value of the status line that is returned to the client
machine from the web server.

Methods:-
Method Description
AddHeader The AddHeader method allows you to add your own HTTP header with a specified
value. If you add an HTTP header with the same name as a previously added header,
the second header will be sent in addition to the first; adding the second header does not
overwrite the value of the first header with the same name. Also, once the header has
been added to the HTTP response, it cannot be removed.

AppendToLog The AppendToLog method adds a string to the end of the Web server log entry for the
current page request. You can only add up to 80 characters at a time, but you can call
this method multiple times.

BinaryWrite The BinaryWrite method writes information directly to the output without any character
conversion.

Clear The Clear method erases any buffered HTML output. It does so without sending any of
the buffered response to the client. Calling Clear will cause an error if Buffer property
of the Response object is not set to True.
End The End method stops the processing of the script in the current page and sends the
already created content to the client. Any code present after the call to the End method
is not processed.

Flush The Flush method sends buffered output to the client immediately. Flush will cause a
run-time error if Buffer property of the Response object is not set to True.

Redirect The Redirect method redirects the user to a different URL.

Write The Write method writes a specified string to the output

6. Explain the two commonly used request methods?(APR.2012)


(a).HTTP Methods:-
The two most used HTTP methods are: GET and POST.
Two commonly used methods for a request-response between a client and server are: GET and POST.
 GET - Requests data from a specified resource
 POST - Submits data to be processed to a specified resource
The GET Method:-
Note that the query string (name/value pairs) is sent in the URL of a GET request:
/test/demo_form.php?name1=value1&name2=value2
Some other notes on GET requests:
 GET requests can be cached
 GET requests remain in the browser history
 GET requests can be bookmarked
 GET requests should never be used when dealing with sensitive data
 GET requests have length restrictions
 GET requests should be used only to retrieve data
The POST Method:-
Note that the query string (name/value pairs) is sent in the HTTP message body of a POST request:
POST /test/demo_form.php
HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
Some other notes on POST requests:
 POST requests are never cached
 POST requests do not remain in the browser history
 POST requests cannot be bookmarked
 POST requests have no restrictions on data length
(b). BinaryRead Method:-
The BinaryRead method is used to retrieve the data sent to the server from the client as part of a POST
request. It will store the data in a safe array (an array that stores information about the number of dimensions
and the bounds of its dimensions).
Note: A call to Request.Form after a call to BinaryRead, and vice-versa, will cause an error.

Syntax:-
Request.BinaryRead(count)
Examples
Parameter Description
Count Requires. Specifies how many bytes to read
from the client

The following example uses the BinaryRead method to place the content of a request into a safe array:
<%
dim a,b
a=Request.TotalBytes
b=Request.BinaryRead(a)
%>

7. Explain the concept of providing security and authentication.(NOV.2014)


Implementing security in a site has the following aspects:
 Authentication : It is the process of ensuring the user's identity and authenticity. ASP.NET allows four
types of authentications:
o Windows Authentication
o Forms Authentication
o Passport Authentication
o Custom Authentication
 Authorization : It is the process of defining and allotting specific roles to specific users.
 Confidentiality : It involves encrypting the channel between the client browser and the web server.
 Integrity : It involves maintaining the integrity of data. For example, implementing digital signature.
Authentication:-
It is the process of ensuring the user’s identity and authenticity. ASP.NET allows four types of authentications:
 Windows Authentication
 Forms Authentication
 Passport Authentication
 Custom Authentication
1. WINDOWS AUTHENTICATION
If your application is targeted for use inside an organization, and users accessing the application have
existing user accounts within the local user database of the Web server or Active Directory, you should
authenticate users with Windows authentication.
2. FORMS AUTHENTICATION
By default, Form authentication is used. Form-based authentication presents the user with an HTML-
based Web page that prompts the user for credentials.
3. PASSPORT AUTHENTICATION
You can also authenticate users using a service from Microsoft called Passport. Passport is a centralized
directory of user information that Web sites can use, in exchange for a fee, to authenticate users. Users can
choose to allow the Web site access to personal information stored on Passport, such as the users' addresses,
ages, and interests.
4. CUSTOM AUTHENTICATION
When standard types of authentication do not meet your requirements, you need to modify an
authentication mechanism to create a custom solution. A user context has principal which represents the identity
and roles for that user. A user is authenticated by its identity and assigned roles to a user determine about
authorization or permission to access resources.

********************************ALL THE BEST*******************************

You might also like