ImageButton.PostBackUrl Propriedade

Definição

Obtém ou define a URL da página que será usada para postagem da página atual quando um usuário clicar no controle ImageButton.Gets or sets the URL of the page to post to from the current page when the ImageButton control is clicked.

public:
 virtual property System::String ^ PostBackUrl { System::String ^ get(); void set(System::String ^ value); };
[System.Web.UI.Themeable(false)]
public virtual string PostBackUrl { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.PostBackUrl : string with get, set
Public Overridable Property PostBackUrl As String

Valor da propriedade

String

A URL da página da Web que será usada para postagem da página atual quando o controle ImageButton for acionado.The URL of the Web page to post to from the current page when the ImageButton control is clicked. O valor padrão é uma cadeia de caracteres vazia (""), que faz com que a página execute postback para si mesma.The default value is an empty string (""), which causes the page to post back to itself.

Implementações

Atributos

Exemplos

O exemplo de código a seguir demonstra como usar a PostBackUrl propriedade para executar uma postagem entre páginas.The following code example demonstrates how to use the PostBackUrl property to perform a cross-page post. Quando o usuário clica no ImageButton controle, a página posta o valor inserido na caixa de texto na página de destino especificada pela PostBackUrl propriedade.When the user clicks the ImageButton control, the page posts the value entered in the text box to the target page specified by the PostBackUrl property. Para executar este exemplo, você também deve criar um arquivo para a página de destino no mesmo diretório que este exemplo de código.To run this sample, you must also create a file for the target page in the same directory as this code example. O código para a página de destino é fornecido no exemplo a seguir.The code for the target page is provided in the next example.

<%@ 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 id="head1" runat="server">
  <title>ImageButton.PostBackUrl Example</title>
</head>
<body>    
  <form id="form1" runat="server">
    
    <h3>ImageButton.PostBackUrl Example</h3>

    Enter a value to post:
    <asp:textbox id="TextBox1" 
      runat="Server">
    </asp:textbox>

    <br /><br />

    <asp:imagebutton id="ImageButton1"
      imageUrl=""
      alternatetext="Post back to this page"
      runat="Server">
    </asp:imagebutton>

    <br /><br />

    <asp:imagebutton id="ImageButton2"
      imageUrl=""
      alternatetext="Post value to another page" 
      postbackurl="ImageButton.PostBackUrlPage2cs.aspx" 
      runat="Server">
    </asp:imagebutton>

  </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>ImageButton.PostBackUrl Example</title>
</head>
<body>    
  <form id="form1" runat="server">
    
    <h3>ImageButton.PostBackUrl Example</h3>

    Enter a value to post:
    <asp:textbox id="TextBox1" 
      runat="Server">
    </asp:textbox>

    <br /><br />

    <asp:imagebutton id="PostImageButton"
      imageUrl="Images\PostButton.jpg"
      alternatetext="Post back to this page"
      runat="Server">
    </asp:imagebutton>

    <br /><br />

    <asp:imagebutton id="CrossPostImageButton"
      imageUrl="Images\CrossPostButton.jpg"
      alternatetext="Post value to another page" 
      postbackurl="ImageButton.PostBackUrlPage2vb.aspx" 
      runat="Server">
    </asp:imagebutton>

  </form>
</body>
</html>

O exemplo de código a seguir demonstra como usar a Page.PreviousPage propriedade para acessar um valor que foi Postado de outra página usando a PostBackUrl propriedade.The following code example demonstrates how to use the Page.PreviousPage property to access a value that was posted from another page using the PostBackUrl property. Esta página Obtém a cadeia de caracteres que foi postada da página anterior e a exibe para o usuário.This page gets the string that was posted from the previous page and displays it to the user. Se você tentar executar este exemplo de código diretamente, receberá um erro porque o valor do Text campo será null .If you attempt to run this code example directly, you will get an error because the value of the Text field will be null. Em vez disso, use esse código para criar uma página de destino e coloque o arquivo no mesmo diretório que o código do exemplo anterior.Instead, use this code to create a target page and place the file in the same directory as the code for the previous example. O nome do arquivo deve corresponder ao valor especificado para a PostBackUrl propriedade no exemplo anterior.The name of the file must correspond to the value specified for the PostBackUrl property in the previous example. Quando você executar o código para o exemplo anterior, esta página será executada automaticamente quando ocorrer a postagem entre páginas.When you run the code for the previous example, this page will execute automatically when the cross-page post occurs.

Observação

O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente para um arquivo code-behind.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. Este exemplo de código deve ser copiado em um arquivo de texto vazio que tenha uma extensão. aspx.This code sample must be copied into an empty text file that has an .aspx extension. Para obter mais informações sobre o modelo de código Web Forms, consulte modelo de código de página do ASP.NET Web Forms.For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

<%@ 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">
  
  void Page_Load (object sender, System.EventArgs e)
  {
    string text;
    
    // Get the value of TextBox1 from the page that 
    // posted to this page.
    text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
    
    // Check for an empty string.
    if (text != "")
      PostedLabel.Text = "The string posted from the previous page is "
                         + text + ".";
    else
      PostedLabel.Text = "An empty string was posted from the previous page.";
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>ImageButton.PostBackUrl Target Page Example</title>
</head>
<body>
  <form id="form1" runat="server">
    
    <h3>ImageButton.PostBackUrl Target Page Example</h3>
      
    <br />
    
    <asp:label id="PostedLabel"
       runat="Server">
    </asp:label>

    </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">
  Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    Dim text As String
    
    ' Get the value of TextBox1 from the page that posted
    ' to this page.
    text = CType((PreviousPage.FindControl("TextBox1")), TextBox).Text
       
    ' Check for an empty string.
    If Not (text = "") Then
      PostedLabel.Text = "The string posted from the previous page is " _
                         & text & "."
    Else
      PostedLabel.Text = "An empty string was posted from the previous page."
    End If
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>ImageButton.PostBackUrl Target Page Example</title>
</head>
<body>
  <form id="form1" runat="server">
    
    <h3>ImageButton.PostBackUrl Target Page Example</h3>
       
    <br />
    
    <asp:label id="PostedLabel"
       runat="Server">
    </asp:label>

    </form>
</body>
</html>

Comentários

A PostBackUrl propriedade permite que você execute uma postagem entre páginas usando o ImageButton controle.The PostBackUrl property allows you to perform a cross-page post using the ImageButton control. Defina a PostBackUrl propriedade como a URL da página da Web a ser postada quando o ImageButton controle for clicado.Set the PostBackUrl property to the URL of the Web page to post to when the ImageButton control is clicked. Por exemplo, especificar Page2.aspx faz com que a página que contém o ImageButton controle seja postada Page2.aspx .For example, specifying Page2.aspx causes the page that contains the ImageButton control to post to Page2.aspx. Se você não especificar um valor para a PostBackUrl propriedade, a página será postada novamente para si mesma.If you do not specify a value for the PostBackUrl property, the page posts back to itself.

Importante

Ao executar um postback de página cruzada com controles com validação do lado do servidor, você deve verificar se a IsValid propriedade da página é true antes de processar o postback.When performing a cross-page postback with controls with server-side validation, you should check that the page's IsValid property is true before processing the postback. No caso de um postback de página cruzada, a página a ser verificada é a inpreviouspagetype.In the case of a cross-page postback, the page to check is the PreviousPage. O código de Visual Basic a seguir mostra como isso é feito:The following Visual Basic code shows how this is done:

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        If Page.PreviousPage.IsValid Then  
            ' Handle the post back  
        Else  
            Response.Write("Invalid")  
        End If  
End Sub  

Para obter mais informações sobre técnicas de postagem entre páginas, consulte postagem entre páginas no ASP.NET Web Forms.For more information on cross-page posting techniques, see Cross-Page Posting in ASP.NET Web Forms.

Esta propriedade não pode ser definida por temas ou temas de folha de estilo.This property cannot be set by themes or style sheet themes. Para obter mais informações, consulte ThemeableAttribute e temas e capas do ASP.net.For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

Aplica-se a

Confira também