把webform数据从一个asp.net 页面提交到另一个页面

方法一:
现在假设有两个页面A、B,我们的目的是把A页面的数据提交到B页面。
首先在A页面建立B页面需要访问A页面的数据项的访问属性。

public string UserName
    {
        
get
        {
            
return textName.Text;
        }
    }

    
public string PassWord
    {
        
get
        {
            
return textPass.Text;
        }
    }

然后再button提交的服务器端事件里
 Server.Transfer("B.aspx");

现在我们来看B页面,在.aspx页面文件中的Page指令下面
<%@ Reference Page="A.aspx" %>
然后再codebehind中,键入如下代码
   A result;//A为A页面的页面类名
    protected void Page_Load(object sender, EventArgs e)
    {
        
string context;
        
if (!Page.IsPostBack)
        {
            result 
= Context.Handler as A;
            context 
= "Name: " + result.UserName + "<br>" + "Password: " + result.PassWord;
            Label1.Text 
= context;
        }
    }

方法二:
在A页面中的提交Button的服务器端事件里添加如下代码:
 Context.Items.Add("UserName", textName.Text);
        Context.Items.Add(
"UserPassword", textPass.Text);
        Server.Transfer(
"B.aspx");


在B页面
方法三:
button控件有一属性:PostBackUrl,可以设置post到哪个页面。
原文地址:https://www.cnblogs.com/cpsing/p/1317598.html