Share via


Page.PreviousPage Propiedad

Definición

Obtiene la página que transfirió el control a la página actual.

public:
 property System::Web::UI::Page ^ PreviousPage { System::Web::UI::Page ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.Page PreviousPage { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PreviousPage : System.Web.UI.Page
Public ReadOnly Property PreviousPage As Page

Valor de propiedad

Page

Page que representa la página que transfirió el control a la página actual.

Atributos

Excepciones

No se permite al usuario actual tener acceso a la página anterior.

o bien

El enrutamiento de ASP.NET está en uso y la dirección URL de la página anterior es una dirección URL enrutada. Cuando ASP.NET comprueba los permisos de acceso, supone que la dirección URL es una ruta de acceso real a un archivo. Dado que este no es el caso con una dirección URL enrutada, se produce un error en la comprobación.

Ejemplos

El ejemplo siguiente se encuentra en dos partes. La primera es una página ASP.NET que usa el Transfer método , expuesto en el modelo de página como Server.Transfer("path"). La segunda parte es la página de destino, que usa la PreviousPage propiedad para obtener el título de la primera página.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    protected void Page_Load(object sender, EventArgs e)
    {
        // If second is an even number, the server is available
        // Replace this line with a valid check for the server.
        bool IsServerAvailable = (DateTime.Now.Second % 2 == 0);
        
        if (!IsServerAvailable)
            Server.Transfer("Notify.aspx", true);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Switch Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>Database Server is Available</h2>
    
    <p>This page appears if the database server 
        is available.</p>
    
    <p>Enter a pretend Server Name: 
        <asp:TextBox ID="serverNameText" 
        runat="server">MyDatabaseServer</asp:TextBox>
    </p>
    
    <p><asp:Button ID="SubmitButton" runat="server" 
        Text="Is server available?" /></p>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, _
        ByVal e As EventArgs)

        Dim IsServerAvailable As Boolean

        ' If second is an even number, the server is available
        ' Replace this line with a valid check for the server.
        IsServerAvailable = (DateTime.Now.Second Mod 2 = 0)

        If Not IsServerAvailable Then
            Server.Transfer("Notify.aspx", True)
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Switch Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>Database Server is Available</h2>
    
    <p>This page appears if the database server 
        is available.</p>
    
    <p>Enter a pretend Server Name: 
        <asp:TextBox ID="serverNameText" 
        runat="server">MyDatabaseServer</asp:TextBox>
    </p>
    
    <p><asp:Button ID="SubmitButton" runat="server" 
        Text="Is server available?" /></p>
    </div>
    </form>
</body>
</html>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    protected void Page_Load(object sender, EventArgs e)
    {
        // Find the server name on the previous page
        TextBox txt = 
                (TextBox)Page.PreviousPage.FindControl("serverNameText");
        if (txt != null)
            prevServerName.Text = Server.HtmlEncode(txt.Text);
        else
            prevServerName.Text = "[Name Not available]";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Page A</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>Database Server is Not Available</h2>

    <p>This page appears if the named database server is not 
    available, but the URL displays as the main target page.</p>
    
    <p>Server Name (From Page.PreviousPage): 
        <asp:Label ID="prevServerName" runat="server" /></p>
    
    <p>Refresh the page to see if the server is now available.</p>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, _
        ByVal e As EventArgs)

        Dim txt As TextBox

        ' Find the server name on the previous page
        txt = CType(Page.PreviousPage.FindControl _
            ("serverNameText"), TextBox)
        If Not IsNothing(txt) Then
            prevServerName.Text = Server.HtmlEncode(txt.Text)
        Else
            prevServerName.Text = "[Name Not available]"
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Page A</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>Database Server is Not Available</h2>

    <p>This page appears if the named database server is not 
    available, but the URL displays as the main target page.</p>
    
    <p>Server Name (From Page.PreviousPage): 
        <asp:Label ID="prevServerName" runat="server" /></p>
    
    <p>Refresh the page to see if the server is now available.</p>
    </div>
    </form>
</body>
</html>

Comentarios

Cuando se usa el Transfer método o se usa la publicación entre páginas para transferir el procesamiento de una página de ASP.NET a otra, la página de origen contiene información de solicitud que podría ser necesaria para la página de destino. Puede usar la PreviousPage propiedad para acceder a esa información.

Si la página actual se representa como resultado de una solicitud directa (no una transferencia o una publicación cruzada de otra página), la PreviousPage propiedad contiene null.

Se aplica a