ASP.Net/Page/PreviousPage — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:53, 26 мая 2010

PreviousPage.FindControl (C#)

   <source lang="csharp">

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

   <title>Untitled Page</title>

</head> <body>

   <form id="form1" runat="server">
       <asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
       <asp:Button ID="Button1" Runat="server" Text="Button"
            PostBackUrl="~/NextPage.aspx" />
   </form>

</body> </html> File: NextPage.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="NextPage.aspx.cs" Inherits="Step2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

   <title>Step 2</title>

</head> <body>

   <form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   </form>

</body> </html> File: NextPage.aspx.cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Step2 : System.Web.UI.Page {

   protected void Page_Load(object sender, EventArgs e)
   {
       if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
       {
           TextBox text = PreviousPage.FindControl("TextBox1") as TextBox;
           if (text != null)
           {
               Label1.Text = text.Text;
           }
       }
   }

}

</source>
   
  


PreviousPage.FindControl (VB)

   <source lang="csharp">

<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

   <title>Untitled Page</title>

</head> <body>

   <form id="form1" runat="server">
       <asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
       <asp:Button ID="Button1" Runat="server" Text="Button"
            PostBackUrl="~/NextPage.aspx" />
   </form>

</body> </html>

File: NextPage.aspx <%@ Page Language="VB" AutoEventWireup="false" CodeFile="NextPage.aspx.vb" Inherits="Step2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

   <title>Step 2</title>

</head> <body>

   <form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   </form>

</body> </html> File: NextPage.aspx.vb Partial Class Step2

   Inherits System.Web.UI.Page
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles Me.Load
       If PreviousPage IsNot Nothing AndAlso PreviousPage.IsCrossPagePostBack Then
           Dim text As TextBox = CType(PreviousPage.FindControl("TextBox1"), TextBox)
           If text IsNot Nothing Then
               Label1.Text = text.Text
           End If
       End If
   End Sub

End Class

</source>