Floating FB popout byF5debug

Interview Questions and Answers on .Net Framework, OOPS, ASP.Net, C#.Net, SQL Server, WCF Series – Part 19

 

Question 181 - What is a State Management in ASP.Net?

State management is the process by which you maintain state and page information over multiple requests for the same or different pages. There are 2 types State Management:

  • Client – Side State Management
  • Server – Side State Management


Question 182 - What are the different management objects available with Client & Server Side Stage Management?

Client – Side State Management

  • View State – Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the Asp.net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.
  • Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state.
  • Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed.
  • Cookies – Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.
  • Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL.

Server – Side State Management

  • Application State - Application State information is available to all pages, regardless of which user requests a page.
  • Session State –Information is available to all pages opened by a user during a single visit.

Both application state and session state information is lost when the application restarts. To persist user data between application restarts, you can store it using profile properties.


Question 183 - How to Pass values between pages?

We can use one of the below options to pass value between 2 pages in ASP.Net.

  • If the value is a String then we can use either one of the following: QueryString, PostBack, Cookies, Session, Cache, Application, Database
  • If the value is a Dataset or an object then we can use either one of the following: (Assuming DTO object not serialized) - Session, Application, Cache


Question 184 - What is a View State?

  • It is a built-in structure for automatically retaining values amongst multiple requests for the same page.
  • The viewstate is internally maintained as a hidden field on the page but is hashed.
  • View State is used to retain the state of server-side objects between post backs.
  • Controls perform well - Label, TextBox, CheckBox, RadioButton, and HyperLink
  • Controls perform less - DropDownList, ListBox, DataGrid, and DataList because of size and large data.
  • Making roundtrips to the server.
  • Item stored in Viewstate exist for the life of the current page. This includes PostBack (to the same page).


Question 185 - What are the Benefits of ViewState?

  • No server resources are required.
  • The values in view state are hashed, compressed, and encoded, thus representing a higher state of security than hidden fields
  • It is good for caching data in Web frame configurations because the data is cached on the client
  • Simple to use

Question 186 - What are the Limitations of ViewState?

  • Page loading and posting performance decreases when large values are stored.
  • Although view state stores data in a hashed format, it can still be tampered because it is stored in a hidden field on the page.


Question 187 - What is an EnableViewState in ASP.Net?

  • EnableViewState turns on the automatic state management feature that enables server controls to re-populate their values on a round trip.
  • Through EnableViewState=true /false we can define whether we have to maintain values of control in hidden fields when page is posted back again and again
  • For example, if you are binding a control to data on every round trip then you do not need the control to maintain its view state, since you will wipe out any re-populated data in any case.
  • Viewstate is enabled for all server controls by default. To disable it, set the EnableViewState property of the control to false.


Question 188 - What are Hidden Fields in ASP.Net?

  • These are html input control with hidden type that store hidden data in the html.
  • The data stored in hidden field is available when form processed on the server or using JavaScript.
  • Syntax - <input type="hidden" name="EVENTTARGET" id="EVENTTARGETID" value="" />
  • Can store only one value in their value property. The value is saved as a string so we need to Typecast.
  • There are two types of server control hidden fields -
        • System.Web.UI.WebControls.HiddenField
        • System.Web.UI.HtmlControls.HtmlInputHidden.


Question 189 - What are the Benefits of Hidden Fields in ASP.Net?

  • Easy to implement
  • Hidden fields are supported by all browsers
  • Faster access of information because data is stored on client side
  • No server resources are required.


Question 190 - What are the Limitations of Hidden Fields in ASP.Net?

  • Not secure because the data is stored on Client side so can be tampered creating a security hole
  • Decreases page performance if too many hidden fields(large data’s)
  • Only support single value and do not support rich structures as HTML.
  • Have to work around with delimiters etc to handle complex structures.


Disclaimer – F5debug Interview Questions & Answers Series:

You may recopy extracts from these pages ("the material") to individual third party websites or to any intranet websites, but only if:

You acknowledge www.f5debug.net as the source of the material. Such acknowledgment should include reference to www.f5debug.net in the copy of the material and should also include “© Karthikeyan Anbarasan, www.f5debug.net ". You inform the third party that these conditions apply to him/her and that he/she must comply with them.

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter