zoukankan      html  css  js  c++  java
  • Application、Session、Server 状态管理

    Application 可以存放任何对象,包括数组.
    以下是Application 存放数组的例子

    前台页面代码:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Application.aspx.cs" Inherits="ApplicationSessionServer_Application" %>

    <!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>
            
    =============================<br />
            Application 可以存放任何对象,包括数组.
    <br />
            以下是Application 存放数组的例子
    <br />
            
    <br />
            
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="存储数组" />
            
    <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="读取数组" /><br />
            
    <br />
            
    <asp:ListBox ID="ListBox1" runat="server" Height="145px" Width="158px"></asp:ListBox></div>
        
    </form>
    </body>
    </html>

    后台代码CS:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class ApplicationSessionServer_Application : System.Web.UI.Page
    {
        
    protected void Page_Load(object sender, EventArgs e)
        
    {

        }

        
    protected void Button1_Click(object sender, EventArgs e)
        
    {
            
    string[] a=new string[4];
            a[
    0= "程序员";
            a[
    1= "教师";
            a[
    2= "工人";
            a[
    3= "司机";
            Application.Add(
    "a",a);//利用 Application 的 Add方法,存储Application
        }

        
    protected void Button2_Click(object sender, EventArgs e)
        
    {
            
    string[] b = (string[])Application["a"];    //强制类型转换.对象转换为数组,然后在 ListBox 中显示出来.
            for (int i = 0; i < b.Length;i++ )
            
    {
                
    this.ListBox1.Items.Add(b[i]);  //利用ListBox 控件显示出来。
            }

        }

    }




  • 相关阅读:
    关于事件的分发与传递
    Android直播app用什么技术可以做到延迟小一些?
    android菜鸟求教eclipse创建avd问题
    安卓APP集成支付宝,调用支付接口,直接退出程序了
    关于蓝牙socket 服务器端首次accept总出错!
    【求助】Android 4.4.2 的WebView的问题
    android 4.0.3开机时不能收到广播
    vue 应用 :关于 ElementUI 的 message 组件
    vue 应用 : 计数器组件
    vue 应用 :多语言显示
  • 原文地址:https://www.cnblogs.com/gfwei/p/533056.html
Copyright © 2011-2022 走看看