C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




ASP.NET Viewstate


Posted Date: 28 Jul 2006    Resource Type: Articles    Category: Web Applications
Author: sourirajan saravananMember Level: Gold    
Rating: Points: 10



=================================================================
Viewstate
=================================================================
What is Viewstate?
It holds a value when a form is posted.

Advantages:

i) No server resources.
ii) Security.
iii) Simplicity.
iv) Flexibility.

Disadvantages:

i) It can have a negative impact on page loading performance, if large amounts of data stored in viewstate.
ii) Does not track across pages. Viewstate information does not automatically transfer from page to page. With the session approach, values can be stored in the session and accessed from other pages. This is not possible with viewstate, so storing data into the session must be done explicitly.
=================================================================
Example for store the value in Viewstate:

Viewstate (“MyName”) = “Saravanan”
Viewstate.Add (“MyName”,”Saravanan”)

Response.Write (Viewstate (“MyName”))
=================================================================
FAQ
=================================================================
Which property of a web page automatically saves the values of the page and of each control before the page is rendered?
Viewstate
=================================================================
What does the ‘EnableViewState’ Property do? Why would I want it on or off?
True, if the control maintains its viewstate; otherwise false.
=================================================================
Where is viewstate information stored?
In HTML Hidden fields
=================================================================
I have a class and I am creating an instance to store that instance in viewstate. How to define this class?
< Serializable()>_ Public Class MyTest
=================================================================
Can we disable the viewstate?
ViewState can be disabled for a single control, for an entire page or for an entire web application. The syntax is:
Disable viewstate for control (Datagrid in this example)
< asp: datagrid EnableViewState="false" ... / >
Disable viewstate for a page, using page directive
< %@ Page EnableViewState="False" ... % >
Disable viewstate for application through entry in web.config
< Pages EnableViewState="false" ... / >
=================================================================
Is it possible to encrypt viewstate when it’s passed over an unencrypted channel?
Yes, Set the EnableViewStateMac to True and either modify the element in Machine.config to look like this:
< machineKey validation=”3DES” …./>
Or Add the following statement to Web.config:
< machineKey validation=”3DES” />
=================================================================
Is it possible to protect viewstate from tampering when it’s passed over an unencrypted channel?
Yes, Simply include an @ Page directive with an EnableViewStateMac=”true” attribute in each ASPX file you wish to protect, or include the following statement in Web.config:
< pages EnableViewStateMac=”true” />
Mac means Message Authentication Code
=================================================================
How to control viewstate on individual controls?
You can set the EnableViewState property of the control. You should disable viewstate for any control that doesn't use it to guarantee optimum performance.
=================================================================
Does the “EnableViewState” allows the page to save the users input on a form
i) Yes
ii) No
=================================================================
What is ViewState used for?
i) ViewState is a property that refers to the next event to be processed.
ii) Any items that you add to ViewState are available within any page and by any user within an application.
iii) ViewState enables you to preserve the values of variables across page requests for a particular user.
iv) ViewState is a control that may be added to the page to store state in.
v) ViewState enables you to preserve the state of a page when posting the page back to itself.
=================================================================
Which one of the following do you use to disable ViewState?
i) < %@ Page ViewStateDisable="true" %>
ii) < %@ Page ViewStateEnable="false" %>
iii) < %@ Page DisableViewState="true" %>
iv) < %@ Page ViewState="false" %>
v) < %@ Page EnableViewState="false" %> (Ans)
=================================================================
How to define a class, which can be stored in viewstate?
I have a class and I am creating an instance to store that instance in viewstate.
How to define this class?
i) Public Class MyTest Inherits Control
ii) Public Class MyTest
iii) Nothing to do. By default it can be used
iv) _ Public Class MyTest (Ans)
=================================================================
Is it possible to encrypt view state when it is passed over an unencrypted channel?
i) Yes, we can encrypt the view state of every page
ii) View State of a page cant be Encrypted coz its already use secure protocols
iii) Can’t say
iv) Yes, Set Enable ViewStateMac to true and either modify the element in Machine.config to look like this or add the following statement to Web.config (Ans)
=================================================================
What type of object is stored in ViewState collection?
i) PanelString
ii) Int64
iii) StateBag (Ans)
iv) ViewState
=================================================================
The name of the hidden field to maintain control state between client requests in ASP.Net page is
i) Viewstate (Ans)
ii) Statement
iii) State
iv) View
=================================================================
How to protect view state from tampering when it’s passed over a un encrypted channel?
i) In page directive set EnableViewStateMac = “true” (Ans)
ii) In Register directive set EnableViewStateMac = “true”
iii) In Web.Config set ProtectViewState = “true”
iv) In IIS set viewstate protection
v) None of the above
=================================================================
Back




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: The secret of ASP.NET 2.0 mobile pages
Previous Resource: Web Chat in AJAX ASP.Net
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use