012-viewstate State hold

Source: Internet
Author: User

State retention scheme for clients: ViewState, hidden fields, Cookies, control status, URL query parameters
Service-side status-preserving scenarios: Session, Application, Caching (cache), database

-"ViewState
-"Example: using the Server Label control, add a button, can achieve +1?"
Looking at the source code and discovering that a span was generated, which is not able to submit data, what exactly happened?
Nature: Hidden Fields
A hidden client control named ViewState is more in the source code, storing the state
-"attribute ViewState: is a property of a collection type that inherits the key value of the control class
Storage: Data that is required on the server side but cannot be submitted to the server
Implements the server-side control
-"Disable ViewState:
Entire page disabled: ViewStateMode = viewstatemode.disabled
Single control Disabled: enableviewstate= "False"
After disabling, you can try the text box +1,label plus 1 is still valid?
-"Summary: Because hidden fields are generated and too much content is stored, it is not recommended to use
Minimize or not use ViewState, server controls

1 <%@ Page Language="C #"AutoEventWireup="true"2 ViewStateMode="Enabled"3 codebehind="ViewStateTest.aspx.cs"Inherits="t4_state.viewstatetest" %>4 5 <!DOCTYPE HTML>6 7 <HTMLxmlns= "http://www.w3.org/1999/xhtml">8 <Headrunat= "Server">9     <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />Ten     <title></title> One </Head> A <Body> -     <formID= "Form1"runat= "Server"> -         <Div> the  -             <Asp:buttonID= "Button1"runat= "Server"OnClick= "Button1_Click"Text= "button" /> -             <Asp:labelID= "Label1"runat= "Server"Text= "0"></Asp:label> -  +         </Div> -     </form> + </Body> A </HTML>
1      Public Partial classViewStateTest:System.Web.UI.Page2     {3         protected voidPage_Load (Objectsender, EventArgs e)4         {5             if(!IsPostBack)6             {7viewstate["YG"] ="Yang too";8             }9         }Ten  One         protected voidButton1_Click (Objectsender, EventArgs e) A         { -Label1.Text = (int. Parse (Label1.Text) +1). ToString (); -             //Label1.Text = viewstate["YG"]. ToString (); the         } -}

012-viewstate State hold

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.