简体   繁体   English

在另一个Web表单中引用另一个Web表单以传递数据

[英]Referencing another a web form in another web form to pass data

I've got a page called webform1 and it has a couple of textboxes and a button and I want to pass the data to a couple of labels on webform2. 我有一个名为webform1的页面,它有几个文本框和一个按钮,我想将数据传递给webform2上的几个标签。

WebForm1 Button: WebForm1按钮:

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

Code behind webform 1: Webform 1背后的代码:

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

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

Webform2 Code Behind: 后面的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 is not letting me reference WebForm1 in WebForm2 without a red line appearing, can anyone see a reason why? Visual Studio不允许我在WebForm2中引用WebForm1而不出现红线,有人可以看到原因吗?

Well, for once, "webForm1" is misspelled, should be "WebForm1". 好吧,一次,“ webForm1”拼写错误,应该是“ WebForm1”。 Also, you can ser the PreviousPageType directive: 同样,您可以服务PreviousPageType指令:

<%@ Page Language="C#" PreviousPageType="WebForm1" %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM