View state FAQ's
Q: What is View state?
Ans: A View state is a hidden element which contains the data of all the controls present on a page in a encrypted manner.
- View state is loaded after Page_Init.
- View state is created after Page_PreRender.
Q: What type of data can be stored in View state variable?
Ans: Any type of data can be stored, but reference type of information needs serialization and deserialization.
Q: How much amount of data can be maintained by using View state variable?
Ans: No limit, but more information is not preferred.
Q: How the View state information can be carried between client and server?
Ans: By using Hidden controls along with request and response.
Q: What is the security protocol used to encrypt View state information?
Ans: Base64 algorithm
Q: What is the meaning of "EnableViewStateMac = true" in page directive?
Ans: It is indication to runtime environment to verify the required security algorithm used for encryption and decryption of viewstate information in machine.config file, instead of using default security algorithm i.e Base64.
Q: What is the StateBag object?
Ans:
- It will hold complete state information of serverside controls, it is created based on the data taken from Hideden control with id __ViewState
- SateBag object is usefull while processing page as well as while rendering page. So that automatic View state can be maintained for server side controls
Q: What is the Hidden control?
Ans: It is like textbox control, which is used to maintain state of server side control.
Q: Where the memory for View state variable is allocated?
Ans: No memory is reserved either at client or at server, data will be transmitted along with request and response in the form of hidden controls.
Q: What are the disadvantages of Viewstate?
Ans:
- Extra information need to be transmitted for each request and response
- Data will be unsecured, since base64 algorithm is known to all
Q: At what level automatic View state can be controlled?
Ans: Automatic View state can be controlled in three levels
1). At control level:
ex:<input type="text" enableviestate="true" id="txt1" runat="server"/>
2). At page level:
goto page directive
<% @page language="cs" enableviewstate="true" %>
3). At Application level:
goto web.config
<system.Web> <pages enableviewstate="true"> </pages> </system.Web>
Q: Is it posssible to maintain automatic View state for password fields?
Ans: No, by default automatic View state is disabled for password fields.