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 控件显示出来。
            }

        }

    }




  • 相关阅读:
    6、加法算术
    5、找出最大和最小的数
    4、计算并输出圆的面积和周长
    2、函数y=f(x)
    1、两数的平方和
    单片机中断寄存器知识点总结
    创建PCB原理图的模板
    电机知识
    结合实例谈谈航拍全景的方法和技巧
    航拍技巧
  • 原文地址:https://www.cnblogs.com/gfwei/p/533056.html
Copyright © 2011-2022 走看看