1 / 21

State Management

State Management. What is State Management? . When you create any web application either in asp, php , jsp , or asp.net all are HTTP based means all are use HTTP protocol.

rudolf
Download Presentation

State Management

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. State Management

  2. What is State Management? • When you create any web application either in asp, php, jsp, or asp.net all are HTTP based means all are use HTTP protocol. • And this protocol is stateless protocol means server dose not aware of that request are coming from same client or new client. • So, how do we make web pages in ASP.Net which will remember about the user, would be able to find out between old clients (requests) and new clients (requests).

  3. Solution of the above problem lies in State Management. • ASP.Net technology offers following two state management techniques. 1) Client side State Management. 2) Server side State Management.

  4. What is Client side State Management? • Client side State Management name shows that all the process depends upon the clients web browser means all the process of State Management will done in Client Side. There are four ways for client side state management.

  5. View State / Control State. • Hidden Fields. • Query String. • Cookies.

  6. View State / Control State. • ASP.Net provides View State/Control State feature to the web forms. View State is used to remember controls state when page is posted back to server. ASP.Net stores view state on client site in hidden field __ViewState in encrypted form.

  7. When page is created on web sever this hidden control is populate with state of the controls and when page is posted back to server this information is retrieved and assigned to controls. You can look at this field by looking at the source of the page (i.e by right clicking on page and selecting view source option.)

  8. <input type="hidden" name="__VIEWSTATE" value="dNrATo45Tm5QzQ7Oz8AblWpxPjE9MMl0Aq765QnCmP2TQ==" /> • You do not need to worry about this as this is automatically handled by ASP.Net. You can enable and disable view state behavior of page and its control by specifying 'EableViewState' property to true and false.

  9. You can also store custom information in the view state as described in following code sample. This information can be used in round trips to the web server.

  10. Example: • C# • // This will save above string in viewstates • ViewState[“Temp”] = “My Name is Amit”; • //Fetching value from view state. • String Vals = ViewState[“Temp”].ToString();

  11. If you take normal html controls and submit the page than that controls does not have view state or control state so they loose the value of controls while in asp.net Microsoft provide this functionality so after submitting page if you take all server controls than they will not leave that data from the textbox or any other controls.

  12. By default, ViewState is enabled for all server controls. ViewState can be enabled and disabled in any of the following ways. • ·         Page Level • ·         Control Level • ·         Application Level / Machine Level

  13. Page Level: • To enable or disable ViewState in the Page Level, use the following in the Page directive of the ASP.NET page. • Example: • <%@ Page EnableViewState ="False" %>  or  <%@ Page EnableViewState ="True" %>

  14. Control Level: • To enable or disable ViewState at the Control Level, use the following: • Example: • <asp:TextBox id="txtName" runat="server” EnableViewState="false" /> or <asp:TextBox id="txtCode" runat="server" EnableViewState="true" />

  15. Application Level: To enable or disable ViewState in the Application Level, use the following: in Web.Config. • Example: • <pages enableViewState="false" /> or <pages enableViewState="true" />

  16. Machine Level: • To enable ViewState in the Machine Level, use the following: in Web.Config. • Example: • <pages enableViewState="true" enableViewStateMac="true" ... /> <machineKey ... validation="3DES" /> or <pages enableViewState="false" ... /> 

More Related