ASP.NET学习之页面传值(8)_Application传值

IndexPage.aspx页面
<form runat="server">
        <div>
            <input id="Text1" type="text" runat="server"/>
            <input id="Text2" type="text" runat="server"/>
            <input id="Button1" value="传值" type="button" runat="server" onserverclick="ok_ServerClick"/>
        </div>
</form>

IndexPage.aspx.cs后台代码:
public void ok_ServerClick(object sender, EventArgs e)
        {
            Application["Name"] = Text1.Value;
            Application["Pass"] = Text2.Value;
            Response.Redirect("ResultIndex.aspx");
        }
ResultPage.aspx.cs后台代码:
protected void Page_Load(object sender, EventArgs e)
  {
  Application对象的作用范围是整个全局,也就是说对所有用户都有效。其常用的方法用Lock和UnLock,
     Application.Lock();
     string name = Application["Name"].ToString();
     string pass = Application["Pass"].ToString(); 
     txt.Value = name + "——————" + pass; 
     Application.UnLock();
  }

参考文献:

http://www.cnblogs.com/liukemng/archive/2010/12/04/1895966.html
http://www.cnblogs.com/xiaoyusmile/archive/2012/03/20/2408797.html
http://www.cnblogs.com/mahaisong/archive/2011/05/23/2054327.html

原文地址:https://www.cnblogs.com/Yisijun/p/4588159.html