View State in ASP.NET Overview
The state of the page held with page and not with the server.
View state is enabled by default for all server controls
HHTP is a stateless protocol, hence the state of the control is not saved between post backs. The information is saved in HTML hidden fields. In other words it is a snapshot of the content page.
There are 2 ways to maintain the viewstate
We can disable viewstate on page level ie.., no state will be kept for any control on the page.In the previous Article I Explained about Inserting Images to Database
To do this,
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="StudentInformationReport.aspx.cs" Inherits="Registration_StudentInformationReport" %>
I can control the viewstate by control by control basis for this I simple add EnableViewState property to the declaration of control.
<asp:TextBox ID="TXT1" runat="server" ViewStateMode="Enabled"></asp:TextBox>
Enableviewstate is property of server controls which is true by default.It means the state of the control is stored in encoded form in hidden textboxes on the page at the time of page submission .
When the page is reloaded the properties are restored from viewstate.
Encryption of ViewState:
ViewState encryption modes
1) Auto.
2)Always.
3)Never.
ViewStateEncryptionMode.Auto:
In this mode,Asp.net will encrypt the viewstate for a page if any control on the page requests it. Note that this means all of the viewstate is encrypted not just the viewstate for the control that requests it.
So encrypting the whole viewstate is faster than doing separate encryption operation if more than one control makes the request
ViewStateEncryptionMode.Never:
In this mode,Asp.net will not encrypt the viewstate, even if the application is set for encryption and controls on the page have requested it.
If you know that no data involved in the page needs to be encrypted, then it may be safe to set Never
ViewStateEncryptionMode.Always:
Asp.Net Doesn’t wait for a control in the page to request encryption.Viewstate is alwaysencrypted.When working with sensitive data, it is a good practice
2 Ways to set this property
<%@ Page Language="C#" AutoEventWireup="true" ViewStateEncryptionMode="Always" CodeFile="StudentInformationReport.aspx.cs" Inherits="Registration_StudentInformationReport" %>
In Web.Config file
<configuration>
<system.web>
<pages viewStateEncryptionMode="Always">
</pages>
</system.web>
</configuration>
Summary :
View state is nothing more than a hidden input which holds a hash of control values. If you view the source of an ASP.NET web form you will see something like this:
<input type="hidden" name="__VIEWSTATE"
value="CEbzzzEnmmz+Bc8IDFlnpgCLJ/HB00...>
Subscribe to:
Post Comments (Atom)
Labels
- Abstraction in Object Oriented Programming (OOPS) Concept (1)
- Access ChildControls in Gridview using Javascript (1)
- Add a WCF Service Reference to the Client (1)
- ASP.Net GridView Highlight Row onmouseover (1)
- ASP.NET View State And ViewStateEncryptionModes Overview (1)
- Calling Javascript From Any Part Of Code Behind Page By Registering The Script (1)
- Check And UnCheck CheckBoxes In Gridview using javascript (1)
- contact your server administrator. (1)
- DataControlField class (1)
- DataKeys ID (Identity Column) in Child Controls events in GridView (1)
- DataList Paging With PagedDataSource (1)
- Declaring Session in Asp.Net (1)
- Difference between Struct and Class (1)
- Displaying Images In GridView From DataBase (1)
- Dynamic Sitemaps in ASP.NET (1)
- Err: You must install Office SharePoint Server 2007 – Please read Microsoft Knowledge Base article: 962935 with the most recent service pack (1)
- GridView Class (1)
- Gridview Inside GridView (1)
- Gridview Paging using C# (1)
- Gridview Sorting Using C# (1)
- GridView.RowDataBound EventEvent (1)
- GridViewRow (1)
- Inserting Images To Database And Display in GridView (1)
- Microsoft Office Sharepoint Server 2007 on Windows Server 2008 – This Program is blocked due to compatibility issues (1)
- ModalPopUp Using CSS and Div To Reduce the Weight On WebPage (1)
- Session State in Asp.Net OverView (1)
- SharePoint 2010 – The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information (1)
- Tooltip GridView Header (1)
- Tree View Menu Control (1)
- WCF Service (12)
- What is Encapsulation in OOPS? (1)
Topics
- Abstraction in Object Oriented Programming (OOPS) Concept (1)
- Access ChildControls in Gridview using Javascript (1)
- Add a WCF Service Reference to the Client (1)
- ASP.Net GridView Highlight Row onmouseover (1)
- ASP.NET View State And ViewStateEncryptionModes Overview (1)
- Calling Javascript From Any Part Of Code Behind Page By Registering The Script (1)
- Check And UnCheck CheckBoxes In Gridview using javascript (1)
- contact your server administrator. (1)
- DataControlField class (1)
- DataKeys ID (Identity Column) in Child Controls events in GridView (1)
- DataList Paging With PagedDataSource (1)
- Declaring Session in Asp.Net (1)
- Difference between Struct and Class (1)
- Displaying Images In GridView From DataBase (1)
- Dynamic Sitemaps in ASP.NET (1)
- Err: You must install Office SharePoint Server 2007 – Please read Microsoft Knowledge Base article: 962935 with the most recent service pack (1)
- GridView Class (1)
- Gridview Inside GridView (1)
- Gridview Paging using C# (1)
- Gridview Sorting Using C# (1)
- GridView.RowDataBound EventEvent (1)
- GridViewRow (1)
- Inserting Images To Database And Display in GridView (1)
- Microsoft Office Sharepoint Server 2007 on Windows Server 2008 – This Program is blocked due to compatibility issues (1)
- ModalPopUp Using CSS and Div To Reduce the Weight On WebPage (1)
- Session State in Asp.Net OverView (1)
- SharePoint 2010 – The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information (1)
- Tooltip GridView Header (1)
- Tree View Menu Control (1)
- WCF Service (12)
- What is Encapsulation in OOPS? (1)
0 Responses to “View State in ASP.NET Overview”
Post a Comment