0% found this document useful (0 votes)
92 views18 pages

U3 QB Solution

The document contains a question bank with multiple choice and short answer questions about advanced web development technologies in ASP.NET. The questions cover topics like viewstate, cookies, sessions, application state, login controls, validation controls and global.asax events. Some key points covered are: 1) Viewstate stores control values on the client-side while session and application state store data on the server-side. 2) Cookies are used to store user information on the client machine while sessions track individual users on the server. 3) Common login controls in ASP.NET include Login, LoginView, LoginStatus and PasswordRecovery controls.

Uploaded by

ashutosh nandani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views18 pages

U3 QB Solution

The document contains a question bank with multiple choice and short answer questions about advanced web development technologies in ASP.NET. The questions cover topics like viewstate, cookies, sessions, application state, login controls, validation controls and global.asax events. Some key points covered are: 1) Viewstate stores control values on the client-side while session and application state store data on the server-side. 2) Cookies are used to store user information on the client machine while sessions track individual users on the server. 3) Common login controls in ASP.NET include Login, LoginView, LoginStatus and PasswordRecovery controls.

Uploaded by

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

T.Y.B.C.A.

(SEM-VI)
Course: US05CBCA21 (Advanced Web Development Technology)
Question Bank
Unit-III

MULTIPLE CHOICE QUESTIONS

1 Which client-side technique is specific to ASP.NET?


a. Cookies b. QueryString c. Viewstate d. Both a and b
Ans: Viewstate
2 Which client-side technique can be disabled by the end-user?
a. Cookies b. Query String c. Viewstate d. Both a and b
Ans: Cookies
3 What is the syntax for creating and using an application variable?
a. Application.VariableName = Value c. Application(VariableName) = Value
b. Application.VariableName = (Value) d. Application(“VariableName”) = Value
Ans: Application(“VariableName”) = Value
4 Which server-side technique is available in ASP.NET?
a. Application states b. Session states c. Database support d. Both a and b.
Ans: Both a and b.
5 An Application variable is created:
a. when the application is first placed on a c. when the first client requests a URL
web server. resource.
b. when the web server is first started. d. every time a client requests a URL
resource.
Ans: when the first client requests a URL resource.
6 A Session variable is created:
a. when the application is first placed on a c. every time a client requests a URL
web server. resource.
b. when the first client requests a URL d. every time a new client interacts with the
resource. web application.
Ans: every time a new client interacts with the web application.
7 We can manage states in asp.net application using
a. Session Objects b. Application c. Viewstate d. Allof the above
Objects
Ans: All of the
above
8 Which of the following ASP.NET object encapsulates the state of the client?
a. Session Object b. Application c. Response Object d. Server Object
Object
Ans: Session Object
9 By default, ASP.NET store SessionIDs in
a Cookies B Cache c Database d Global Variable
Ans: Cookies
10 You need to store state data that is accessible to any user who connects to your Web
application. Which object should you use?
a. Session b. Application c. Response Cookies d. Response
Viewstate
Ans: Application

11 allows executing ASP.NET application level events and setting application-


level variables.
1
a. Application b. Global.asax file c. Impersonation d. Web.config file
object
Ans: Global.asax file
12 event is fired just before an application is destroyed.
a.Application_Error b. Application_Disposed
c. Application_End d.Application_EndRequest

Ans Application_Disposed

13 Which property is used to check whether the validation is successful or not?


a. ControlToValidate b. IsValid c. ControlValid d. None of these
Ans. b. IsValid
14 is the Single-Selection Control in ASP.NET IDE?
a. List Box b. Drop Down List c. Both a & b d. None of these
Ans. b. Drop Down List

15. By which control, we can save the file from client-side to server-side?
a. Adrotator b. Hyper link c. File Upload d. Save File
Ans. c. File Upload

16. How many RadioButtons in a Group Box can be selected at the same time?
a. 0 b. 1 c. More than 1 d. None of these
Ans. b. 1

17. Which property specifies what input Web control is validating?


a. ControlToValidate b. IsValid c. ControlValid d. None of these
Ans. a. ControlToValidate

18. __________value is set for CauseValidation property, to post the page without checking
validation on button click event.
a. Yes b. False c. -1 d. 2
Ans. b. False

19. Which validation control is used to put all error messages in one spot on the page?
a. RequireField b. Custom Validator c. Validation Summary d. Regular
Validator Expression
Validator
Ans. c. Validation Summary

20. validation control is used to check that user has entered a valid
email address?
a. RequireField b. Custom Validator c. Validation Summary d. Regular
Validator Expression
Validator
d. Regular Expression Validator

21. validation occurs, on changes the value of CausesValidation property of button.


a. Client-Side b. Server-Side c. Both a & b d. None of these
Ans. b. Server-Side

2
Short Questions:- ( 2 Marks)
1) Define View State.

ViewState is an important client side state management technique. ViewState does not hold the
controls; it holds the values of controls. ViewState can hold the value on single web page, if we
go to other page using response.redirect then ViewState will be null.

2) Define Cookies.

Cookie is a small piece of text information which is stored on user hard drive using users
browser for identify users. It is used to store information like Username, Password, City and
PhoneNo etc on client machines. Cookie does not use server memory.

3) Define Session state.

Session is a server side state management technique. It can be stored either on an Internet
Information Service (IIS) server that is by default our "inproc" mode or it can be stored in a
state or SQL Server that is our "outproc" mode. Session state variables are stored on the web
server by default and kept for the life time of a session.

4) Define Application state.

Application State is a server side state management technique. Application State is stored in the
memory of the server and is faster than storing and retrieving information in a database.
Application State is for all users and sessions. Application State does not have a default
expiration period.

5) List Basic Application events used in Global.asax

1. Application_Start()
2. Application_BeginRequest()
3. Application_AuthenticateRequest()
4. Application_Error()
5. Application_End()
6. Application_Disposed()

6) List Login Controls used in ASP.NET.

1. Login
2. LoginView
3. LoginStatus
4. Loginname
5. PasswordRecovery
6. ChangePassword
7. CreateUserWizard 

7) Explain Login Control.

The Login control provides a user interface which contains username and password that authenticate
the username and password.

3
Properties of the Login Control

1. CreateUserUrl
2. Password
3. FailureText

8) Explain LoginView control.

The LoginView Control is used to display two different views of a web page. It depends on whether the
any user has logged on to a web page as anonymous user or registered user.

 Anonymous Template :-   This template (default of all) will be displayed when any user just open
the web page but not logged in.
 LoggedInTemplate:- This Template (page)will be displayed when the user in logged in.

9) Explain PasswordRecovery control.

It is used to recover or reset the password for the user. The password is sent through an email as a
message at the registration time.
The control contains the following three views.

1. Question
2. UserName
3. Success

4
10) Explain LoginStatus control.

It specifies that a particular user has logged into the web site. The login status is displayed as a
text. The login text is displayed as a hyperlink but provides the navigation to the login page.
The LoggedIn and LoggedOut are the two status provided by the LoginStatus control.

Methods of the LoginStatus Control

1. OnLoggedOut
2. OnLoggingOut

Events of the LoginStatus Control

1. LogginOut
2. LoggedOut

11) Explain LoginNames control.

It is used for displaying the name of the authenticated users. The control is not displayed if it does not
contain any logged in user. The LoginName class is used for the control.

The control does not contain any method or events associated with it. The FormatString property is used
for displaying the string in the control.

12) Explain CreateUserWizard control.

The control is used for creation of a new user. The control can be extended to the existing Wizard
control. The control can be customized through templates and properties.

Properties of the Control

1. Answer
2. CompleteStep
3. ContinueButtonText
4. Email
5
5. LoginCreatedUser

Events of the control

1. CreatedUser
2. CreatingUser
3. SendingMail
4. SendMailError

13) Explain ChangePassword control.

Using this control, user can easily change your existing password. This control prompts uses to
provide the current password first and then set the new password first and then set the new password. If
the old password is not correct then new password can't be set. This is also helps to send the email to the
respective users about the new password.

14) Differentiate between Session and Application.

Session Application
1 Session object is used to maintain the session of each Application object is used to store data which
user. available across the entire application and shared
across multiple users sessions.
2 Session State has a less lifetime. Application State has a much longer lifetime.
3 Session state variables are cleared, when the user Application state variables are cleared, when
session time out. the process is restarted.
4 Session state   is user and browser specific. Application   state is application specific.
5 Session state can   be stored in memory on the server Application   state is stored only in the memory on
as well as client’s cookies. the server.

15) List different types of Validation controls.

 RequiredFieldValidator Control
 CompareValidator Control
 RangeValidator Control
 RegularExpressionValidator Control
 CustomFieldValidator Control
 ValidationSummary

16) Differentiate between RequiredFieldValidator & RangeValidator.

RequiredFieldValidator RangeValidator
1 It ensures that the required field is not empty. It verifies that the input value falls within a
predefined range.
2 Properties: Properties:
ControlToValidate ControlToValidate
ErrorMessage ErrorMessage
Text Text
Minimum Value
Maximum Value
Type
6
3 Example Example

17) Differentiate between Clientside Validation & Serverside Validation.

Client side Validation Server side Validation


1 The user input validation is take place on the The user input validation is take place on the
client side (web browser) is called client side server side is called server side validation.
validation.
2 It doesn’t require a postback. It occurs during a postback session is called.
3 If the user request doesn’t require any server If the user request requires any server resources
resources to validate the input then it can be to validate the input then it can be used.
used.
4 It can be using client side scripting languages It can be using server side scripting languages
such as JavaScript, VBScript, HTML5 etc. such as ASP.NET, PHP, JAVA, Python etc.
5 It is simple, quick and faster. It is slower for client side.
6 Less Secure. More secure.

Long Questions:-

1) What is view state? Explain with example.

ViewState is an important client side state management technique. ViewState is used to store
user data on page at the time of post back of web page. ViewState does not hold the controls; it
holds the values of controls. It does not restore the value to control after page post back.
ViewState can hold the value on single web page, if we go to other page using response.redirect
then ViewState will be null. ViewState stores data on single page.
View State Example in ASP.Net

protected void btnclear_Click(object sender, EventArgs e)


{
ViewState["name"] = txtname.Text;
txtname.Text = "";
}
protected void btndisplay_Click(object sender, EventArgs e)
{

7
lbl.Text = ViewState["name"].ToString();
}

2) What is Cookies? Explain in detail with Example.

Cookie is a small piece of text information which is stored on user hard drive using users
browser for identify users. It is used to store user preference information like Username,
Password, City and PhoneNo etc on client machines. Cookie does not use server memory.
Ways to store cookies
1. Cookies collection
2. HttpCookie object
Types of Cookies
1. Persistence Cookie
2. Non-Persistence Cookie

1. Persistence Cookie
These types of cookies are permanently stored on user hard drive.
Cookies which have an expiry date time are called persistence cookies

2. Non-Persistence Cookie
These types of cookies are not permanently stored on user hard drive. It stores the information up to the
user accessing the same browser. When user closes the browser the cookies will be automatically
deleted.
Example:

Create Cookie Button C# Code

protected void btncreate_Click(object sender, EventArgs e)


{
Response.Cookies["name"].Value = txtcreatecookie.Text;
Response.Cookies["name"].Expires = DateTime.Now.AddMinutes(1);
Label1.Text = "Cookie Created";
8
txtcreatecookie.Text = "";
}

Here, we create cookie with name parameter and assign textbox values to name cookie and also set
expiry time 1 minute. The cookie destroyed after 1 minute.

Retrieve Cookie Button Code


protected void btnretrieve_Click(object sender, EventArgs e)
{
if (Request.Cookies["name"] == null)
{
txtretrieve.Text = "No cookie found";
}
else
{
txtretrieve.Text = Request.Cookies["name"].Value;
}
}

On retrieve cookie button checks if cookie value not null then display cookie value in result, but after 1
minute the cookie expires, after 1 minute cookie value will be null and result will be “No cookie found”.

Advantages of Cookies

 It’s clear text so user can able to read it.


 We can store user preference information on the client machine.
 It is easy to maintain.
 Fast accessing.

Disadvantages of Cookie

 If user clears cookie information we can't get it back.


 No security.
 Each request will have cookie information with page.

Cookie Limitations
1. Most browsers support cookies of up to 4096 bytes(4KB)
2. Most browsers allow only 20 cookies per site; if you try to store more, the oldest cookies
are discarded.
3. Browser supports 300 cookies towards different websites.
4. Complex type of data not allowed (e.g: dataset), allows only plain text (i.e, cookie allows
only string content)
5. Cookies are browser specific.

3) Explain Session State in detail with example.

Basically a session is a variable used between the client and the server that is stored on the server
side. Now it can be stored either on an Internet Information Service (IIS) server that is by default
9
our "inproc" mode or it can be stored in a state or SQL Server that is
our "outproc" mode. Session state variables are stored on the web server by default and kept for
the life time of a session. Default time is 20 Minutes.

Each created session is stored in SessionStateItemCollection object. We can get current session


value by using Session property of Page object. 

ASP.NET Session Events

There are 2 types of events available in ASP.NET. We can handle both sessions in a global.asax file.

1. Session_Start(): When the new session is initialized then the session_start event is raised.
2. Session_end(): When the session is Expires then the Session_End event raised.

Session state is generally used for storing application data such as inventory, supplier list,
customer record, or shopping cart. Sessions are identified and tracked with a 120-bit
SessionID, which is passed from client to server and back as cookie or a modified URL.
The SessionID is globally unique and random. from the HttpSessionState class, which
defines a collection of session state items.

The HttpSessionState class has the following properties:

Properties
SessionID
Item(name)
Count
TimeOut

The HttpSessionState class has the following methods:

Methods
Add(name, value)
Clear
Remove(name)
RemoveAll
RemoveAt

Example:
This application will store user email to the session when user login.

10
protected void login_Click(object sender, EventArgs e)  
        {  
            if (password.Text=="123")  
            {  
                // Storing email to Session variable  
                Session["email"] = email.Text;  
            }  
            // Checking Session variable is not empty  
            if (Session["email"] != null)  
            {  
                // Displaying stored email  
                Label3.Text = "This email is stored to the session.";  
                Label4.Text = Session["email"].ToString();  
            }  
        }  

4) Explain Application State in detail with Example.

Application State is a server side state management technique. Application State does not have a
default expiration period. When we close the worker process the application object will be lost.
Application state allows you to store global objects that can be accessed by any client.
Application state is based on the System.Web.HttpApplicationState class.

Mostly people use this Application state for the reasons given below.

1. Counting clicking.
2. Store common data
3. To display total online users.
4. Total orders received. Etc.

The events of the Global.asax file are:

1. Application_Start()
2. Application_BeginRequest()
3. Application_AuthenticateRequest()
4. Application_Error()
5. Application_End()
6. Application_Disposed()

11
Example of Application State in ASP.Net

Here, we calculate total visit of uses visited web page by clicking “Click to Visit” button.
C# Code for Example
protected void btnvisit_Click(object sender, EventArgs e)
{
int count = 0;
if (Application["Visit"] != null)
{
count = Convert.ToInt32(Application["Visit"].ToString());
}
count = count + 1;
Application["Visit"] = count;
Label1.Text = "Total Visit = " + count.ToString();
}

Here, above output screen we use different browser for visit same page. The result counter value stored
in Application object so it would be changed simultaneously for both visitors.
In above case some time too many users click button at the same time that time result won’t be accurate.
This situation known as dead lock. To avoid dead lock we use Lock() and UnLock() in application state.

5) Explain Application events used in Global.asax in Detail.

Application_Start() : This method is invoked initially when first application domain is created.

Application_BeginRequest() : After an application has started the first method is executed for
every user.

Application_AuthenticateRequest() : It checks to determine whether or not the user is valid.

Application_Error() : Whenever an unhandled exception occurs then this event will be called.

Application_End() : This method is called before the application ends.

Application_Disposed() : This event is called after the application will be shut down.

6) Explain in detail Login Control with example.

The Login control provides a user interface which contains username and password that
12
authenticate the username and password and grant the access to the desired services.

The Login class contains various methods


1. CreateChildControls
2. OnLoggingIn
3. OnLoggedIn
4. OnAuthenticate

Properties of the Login Control

1. CreateUserIconUrl
2. CreateUserUrl
3. DisplayRememberMe
4. FailureText
5. HelpPageText
6. Password

Events of the Login Control

1. LoggedIn
2. LoggingIn
3. LoginError

The Login control at the design time is as shown below:

7) Explain session and application state in detail. Also differentiate them.


Already covered in previous questions.

8) Explain following controls with its properties, methods and events.

Common Properties of validation controls:


Property Description
ControlToValidate Gets or sets the input control to validate.
ErrorMessage Gets or sets the text for the error message displayed in a ValidationSummary control when
validation fails.
ForeColor Gets or sets the color of the message displayed when validation fails.
IsValid Gets or sets a value that indicates whether the associated input control passes validation.
Text Gets or sets the text displayed in the validation control when validation fails. 

13
Common Methods of validation controls:
Property Description
Validate It performs validation on the associated input control and updates the
IsValid property.

a) RequiredFieldValidator control

This is the simplest validation control that makes sure that the users have entered
data into a Data-entry control. If they omit to enter a value, this validation control
will display its error message.
This control has an Initial value property, which is set to an empty string (“”) by
default. If the data has not changed from that value when validation occurs, the
control displays its error message.

Example

b) RangeValidator control

A Range validator tests if thevalue of a Data-Entry control is inside a specified


range of values.

Property Description
MaximumValue Specifies the maximum value of the input control
MinimumValue Specifies the minimum value of the input control

Type Specifies the data type of the value to check. The types are:
 Currency
 Date
 Double
 Integer
 String

Example

14
c) CompareValidator control

A CompareValidator compares the value entered by the user into a Data-Entry


control with the value entered into another Data-Entry control. Set the
ControlToCompare property to specify the control to compare with.

Property Description
ControlToCompare The name of the control to compare with
Operator The type of comparison to perform. The operators
are:
 Equal
 GreaterThan
 GreaterThanEqual
 LessThan
 LessThanEqual
 NotEqual
 DataTypeCheck
ValueToCompare A specified value to compare with

Example

d) RegularExpressionValidator control

A RegularExpresson validator control is used to check if the value in Data-Entry


control matches a pattern defined by a regular expression.

Property Description
ValidationExpression Specifies the expression used to validate input control.

Example:

15
e) CustomValidator control

ASP.Net also allows the freedom of writing your own validator.

The custom validation code is written in a function in the code-behind page. Custom validation can be
done either at the client-side or the server-side. With a custom validator, you set the
ClientValidationfunction property to the names of a script function, such as Javascript or VBscript
function.
Properties:

Property Description
ClientValidationFunction Specifies the name of the client-side validation script function to be
executed. 
ValidateEmptyText Sets a Boolean value indicating whether empty text should be
validated.
Events:
Property Description
ServerValidate It occurs when validation takes place on the server.

Example:

We will simply check the length of the string in the TextBox.

protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e)


{
if(e.Value.Length > 50)
e.IsValid = true;
else
e.IsValid = false;
}

f) ValidationSummary control

The Validationsummary control, which summarize the error messages from all
validators on a web page in one location.
Properties:

16
Property Description
DisplayMode How to display the summary. Legal values are:
 BulletList
 List
 SingleParagraph
HeaderText A header in the ValidationSummary control
ShowMessageBox A Boolean value that specifies whether the summary should be
displayed in a message box or not
ShowSummary A Boolean value that specifies whether the ValidationSummary
control should be displayed or hidden
Example:

17
18

You might also like