0

我有一个名为 webform1 的页面,它有几个文本框和一个按钮,我想将数据传递给 webform2 上的几个标签。

WebForm1 按钮:

    <asp:Button ID="btnCrossPage" runat="server" Text="Button" PostBackUrl="~/Webform2.aspx" />

网络表单 1 背后的代码:

        public partial class webform1 : System.Web.UI.Page
    {

    }
    public string Name
    {
      get{ return txtName.Text;}
    }
     public string Email
    {
      get{ return txtEmai.Text;}
    }

Webform2 代码背后:

    public partial class Webform2: System.Web.UI.Page
    { 
      Webform1 pPage = (Webform1)this.PreviousPage;
      if(pPage != null && pPage.IsCrossPagePostBack)
      {
             lblName.Text = pPage.Name;
             lblEmail.Text = pPage.Email;
      }

Visual Studio 不允许我在没有出现红线的情况下在 WebForm2 中引用 WebForm1,任何人都可以看到原因吗?

4

1 回答 1

0

好吧,有一次,“webForm1”拼写错误,应该是“WebForm1”。此外,您可以使用 PreviousPageType 指令:

<%@ Page Language="C#" PreviousPageType="WebForm1" %>
于 2014-05-18T13:33:43.727 回答