zoukankan      html  css  js  c++  java
  • ViewState 视图状态对象实例

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoViewState.aspx.cs" Inherits="WebApplication1.DemoViewState" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="增长" />
            <br />
            <br />
            <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="加1" />
        
        </div>
        </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplication1
    {
        public partial class DemoViewState : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
            public int i = 0;
            protected void Button1_Click(object sender, EventArgs e)
            { 
                i++;
                Response.Write(i); 
            }
    
            protected void Button2_Click(object sender, EventArgs e)
            {
                //ViewState 视图状态对象,它的数据是存在在页面的那个隐藏域
                if (ViewState["count"] == null)
                {
                    ViewState["count"] = 10;
                }
                else
                {
                    int x = Convert.ToInt32(ViewState["count"]);
                    x++;
                    ViewState["count"] = x;
                }
                Response.Write(ViewState["count"]);
            }
        }
    }
  • 相关阅读:
    JSON解析之——Android
    Xml解析之——Java/Android/Python
    Design Pattern —— Singleton
    设计模式(10)--观察者模式
    设计模式(9)--建造者模式
    设计模式(8)--外观模式
    设计模式(7)--模板模式
    设计模式(6)--原型模式
    设计模式(5)--工厂模式
    设计模式(4)--代理模式
  • 原文地址:https://www.cnblogs.com/xiaz/p/5242512.html
Copyright © 2011-2022 走看看