页面间的数据传递技术

来源:互联网 发布:淘宝开店实名认证 晚上 编辑:程序博客网 时间:2024/05/13 05:12

一、post
1、将表单的form id="form1" runat="server" method="post"主要提交的方式是Post方法
2、将表单中按钮的PostBackUrl属性设置为要提交的页面index.aspx(指示提交的位置)
3、在提交页面中的Request.Form["提交数据的ID"]取出提交的数据

二、get
将表单的form id="form1" runat="server" method="get"主要提交的方式是get方法
将按钮的PostBackUrl属性设置为要提交的页面index.aspx(指示提交的位置)
在提交页面中的Request.QueryString["提交数据的ID"]取出提交的数据


三、模仿get
    protected void Button1_Click(object sender, EventArgs e)
    {
        //方法用处很多,关键是很灵活
        Response.Redirect("index.aspx?txtID="+this.TextBox1.Text);
    }

四、页面整体提交
1、<asp:Button ID="btnPage" runat="server" Text="页面整体提交" PostBackUrl="index.aspx" />
2、获得数据
        if (!Page.IsPostBack)
        {
            //取得前一个页面整体提交的数据 Page.PreviousPage
            TextBox tb = (TextBox)Page.PreviousPage.FindControl("txtID");
            lblMessage.Text = tb.Text;
        }

原创粉丝点击