ASP.NET学习之页面传值(4)_Context传值
IndexPage.aspx页面: 必须在<form runat="server">中 <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) { //将要传递的值存放在Context中 Context.Items["name"] = Text1.Value; Context.Items["pass"] = Text2.Value; //页面跳转 Server.Transfer("ResultIndex.aspx"); } ResultPage.aspx.cs后台代码: 接收数据 protected void Page_Load(object sender, EventArgs e) { string name = Context.Items["name"].ToString(); string pass = Context .Items["pass"].ToString(); txt.Value = "用户名:" + name + "-----密码:" + pass; }