zoukankan      html  css  js  c++  java
  • Session 传值

    Session

    保存在服务器上
    很安全
    占用服务器资源
    只有会话模式   20分钟生命周期
    可以存任意数据类型,Object,取的时候需要类型转换
    服务器内存

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Default1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += Button1_Click;
        }
    
        void Button1_Click(object sender, EventArgs e)
        {
            string uname = TextBox1.Text;//获取用户输入的用户名   
            string pwd = TextBox2.Text;//获取用户输入的密码
            Users u = new UsersData().SelectUser(uname, pwd);
            Session["hehe"] = u;//传值
            Response.Redirect("Default5.aspx");//跳到Default5.aspx
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Default5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["hehe"] != null)//不为空的时候执行
                Label1.Text = (Session["hehe"] as Users).NickName;//接受传过来的值  Session["hehe"] as Users变成对象
        }
    }
  • 相关阅读:
    Xcode4快速Doxygen文档注释 — 简明图文教程(3分钟后爽歪歪)
    ACE小记
    【C++】获得本机所有网卡的IP和MAC地址信息(转)
    一周好文(11)
    cocos2d‘s replaceScene
    iPhone 真机调试安装流程
    金牌银牌铜牌
    整数分割(摘抄)

    马拦过河卒
  • 原文地址:https://www.cnblogs.com/skyhorseyk/p/7299544.html
Copyright © 2011-2022 走看看