zoukankan      html  css  js  c++  java
  • ViewState

    Each control on a Web Forms page, including the page itself, has a ViewState property that it inherits from the base Control class. View state 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.

    You can use the ViewState property to save your values independent of control state between round trips to the server. The ViewState property is stored in the page in a hidden form field.

    Note   In order to use the ViewState property, your form must have a server form element (
    <form runat="server">
    ). For usage recommendations, see State Management Recommendations.

    To store information in view state

    • Create and store a new element in the ViewState property.
      Note   The data must be in a format compatible with view state. For example, to store a dataset in view state, you should first convert it to a string representation.
      ' Visual Basic
      ViewState("color") = "yellow"
      
      // C#
      ViewState["color"] = "red";
      

    To retrieve information from view state

    • Get the value of an element by specifying its name. Cast the object in view state to the type that you need it to be.

      The following example shows how you can retrieve a value stored earlier under the ViewState name "color." Note that the value is cast to a string.

      ' Visual Basic
      Dim strColor as String
      strColor = CStr(ViewState("color"))
      
      // C#
      string strColor;
      strColor =(string)ViewState["color"];
      
  • 相关阅读:
    ts 与 C#的 一个差异的地方
    .net core的 几个模板比较
    iOS 绘画学习(3)
    在你的iPad上调整图片尺寸
    Pholio应用开发指南:通过平铺组成大的图片
    学会爱上iOS自动布局(Auto Layout)
    iOS 绘画学习(2)
    iOS 绘画学习(1)
    iOS 证书管理、验证、打包流程
    UIScrollView 技巧(2)
  • 原文地址:https://www.cnblogs.com/sandy_liao/p/1908837.html
Copyright © 2011-2022 走看看