不同页面之间传值除了Cookie,Session之外,还可以使用页面的上下文对象

来源:互联网 发布:c语言中实参和形参 编辑:程序博客网 时间:2024/05/17 00:56
    如何在一个页面中显示另外一个页面:
    <body>
        <form id="form1" runat="server">
        <iframe src="WebForm.aspx" style="width:500px; height:400px"></iframe>
        </form>
    </body>
----------------------------------------------------------------------------------------------------
    如何使用HttpContext传递页间数据:
    WebForm1:
    protected void Button1_Click(object sender, EventArgs e)
    {
        string data = "世界你好";
        this.Context.Items.Add("DATA",data);
        //不能使用this.Response.Redirect("WebForm1.aspx"),地址栏的URL不变
        this.Server.Transfer("WebForm1.aspx");
    }

    WebForm2:
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Response.Write(this.Context.Items["DATA"].ToString());
    }
 

原创粉丝点击