U3 QB Solution
U3 QB Solution
(SEM-VI)
Course: US05CBCA21 (Advanced Web Development Technology)
Question Bank
Unit-III
Ans Application_Disposed
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
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
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.
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.
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.
1. Application_Start()
2. Application_BeginRequest()
3. Application_AuthenticateRequest()
4. Application_Error()
5. Application_End()
6. Application_Disposed()
1. Login
2. LoginView
3. LoginStatus
4. Loginname
5. PasswordRecovery
6. ChangePassword
7. CreateUserWizard
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
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.
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.
1. OnLoggedOut
2. OnLoggingOut
1. LogginOut
2. LoggedOut
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.
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.
1. Answer
2. CompleteStep
3. ContinueButtonText
4. Email
5
5. LoginCreatedUser
1. CreatedUser
2. CreatingUser
3. SendingMail
4. SendMailError
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.
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.
RequiredFieldValidator Control
CompareValidator Control
RangeValidator Control
RegularExpressionValidator Control
CustomFieldValidator Control
ValidationSummary
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
Long Questions:-
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
7
lbl.Text = ViewState["name"].ToString();
}
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:
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.
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
Disadvantages of Cookie
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.
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.
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.
Properties
SessionID
Item(name)
Count
TimeOut
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();
}
}
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.
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.
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_Error() : Whenever an unhandled exception occurs then this event will be called.
Application_Disposed() : This event is called after the application will be shut down.
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.
1. CreateUserIconUrl
2. CreateUserUrl
3. DisplayRememberMe
4. FailureText
5. HelpPageText
6. Password
1. LoggedIn
2. LoggingIn
3. LoginError
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
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
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
Property Description
ValidationExpression Specifies the expression used to validate input control.
Example:
15
e) CustomValidator control
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:
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