PostBackOptions Classe

Definição

Especifica como o JavaScript do cliente é gerado para iniciar um evento de postback.Specifies how client-side JavaScript is generated to initiate a postback event.

public ref class PostBackOptions sealed
public sealed class PostBackOptions
type PostBackOptions = class
Public NotInheritable Class PostBackOptions
Herança
PostBackOptions

Exemplos

O exemplo de código a seguir usa o OnClick evento de um Button controle para gerar um script do lado do cliente para um HyperLink controle que permitirá que o HyperLink controle cause um evento de postback.The following code example uses the OnClick event of a Button control to generate client-side script for a HyperLink control that will allow the HyperLink control to cause a postback event. Como a ActionUrl Propriedade do myPostBackOptions objeto é definida como "página2. aspx", o postback publicará a página Web Forms em outra página chamada "página2. aspx", que não é fornecida aqui.Because the ActionUrl property of the myPostBackOptions object is set to "Page2.aspx", the postback will post the Web Forms page to another page named "Page2.aspx", which is not provided here. Para usar este exemplo, você deve adicionar outra página da Web chamada "página2. aspx" ao seu projeto ou diretório.To use this example, you must add another Web page named "Page2.aspx" to your project or directory.

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 postbackoptionscs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            Label1.Text = "A postback event has occurred.";
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        // Create a new PostBackOptions object and set its properties.
        PostBackOptions myPostBackOptions = new PostBackOptions(this);
        myPostBackOptions.ActionUrl = "Page2.aspx";
        myPostBackOptions.AutoPostBack = false;
        myPostBackOptions.RequiresJavaScriptProtocol = true;
        myPostBackOptions.PerformValidation = true;

        // Add the client-side script to the HyperLink1 control.
        HyperLink1.NavigateUrl = Page.ClientScript.GetPostBackEventReference(myPostBackOptions);

        Label1.Text = "Click this hyperlink to initiate a postback event.";
    }
}
Partial Class postbackoptionsvb
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        ' Create a new PostBackOptions object and set its properties.
        Dim myPostBackOptions As PostBackOptions = New PostBackOptions(Me)
        myPostBackOptions.ActionUrl = "Page2.aspx"
        myPostBackOptions.AutoPostBack = False
        myPostBackOptions.RequiresJavaScriptProtocol = True
        myPostBackOptions.PerformValidation = True

        ' Add the client-side script to the HyperLink1 control.
        HyperLink1.NavigateUrl = Page.ClientScript.GetPostBackEventReference(myPostBackOptions)

        Label1.Text = "Click this hyperlink to initiate a postback event."

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Page.IsPostBack Then
            Label1.Text = "A postback event has occurred."
        End If

    End Sub
End Class

O exemplo de código a seguir é uma página da Web que pode ser usada para executar o arquivo code-behind anterior.The following code example is a Web page that can be used to run the preceding code-behind file.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="postbackoptions.aspx.cs" Inherits="postbackoptionscs" %>

<!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>PostBackOptions Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
    <h3>PostBackOptions Example Page</h3>
      Click this button to create client-side script for the 
      Postback hyperlink that causes a postback event to occur.
      <br />
      <asp:Button id="Button1" 
        runat="server" 
        text="Create Script" 
        onclick="Button1_Click" />
      <br /><br />
      <asp:Label id="Label1" 
        runat="server" 
        text="">
      </asp:Label>
      <br />
      <asp:HyperLink id="HyperLink1" 
        runat="server" 
        text="Postback">
      </asp:HyperLink>
    </form>
  </body>
</html>
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="postbackoptions.aspx.vb" Inherits="postbackoptionsvb" %>

<!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>PostBackOptions Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
    <h3>PostBackOptions Example Page</h3>
      Click this button to create client-side script for the 
      Postback hyperlink that causes a postback event to occur.
      <br />
      <asp:Button id="Button1" 
        runat="server" 
        text="Create Script" 
        onclick="Button1_Click" />
      <br /><br />
      <asp:Label id="Label1" 
        runat="server" 
        text=""></asp:Label>
      <br />
      <asp:HyperLink id="HyperLink1" 
        runat="server" 
        text="Postback"></asp:HyperLink>
      <br />
    </form>
  </body>
</html>

Comentários

A PostBackOptions classe permite que os controles emitam um script do lado do cliente que inicia um evento de postback.The PostBackOptions class allows controls to emit client-side script that initiates a postback event. A PostBackOptions classe também fornece uma referência ao controle que iniciou o evento de postback por meio da TargetControl propriedade.The PostBackOptions class also provides a reference to the control that initiated the postback event through the TargetControl property. O evento de postback é criado com base nas opções especificadas no PostBackOptions objeto passado para o ClientScriptManager.GetPostBackEventReference método.The postback event is created based on the options specified in the PostBackOptions object passed in to the ClientScriptManager.GetPostBackEventReference method.

Normalmente, um postback para o servidor é iniciado por elementos como um botão enviar ou um botão de imagem.Normally, a postback to the server is initiated by elements such as a Submit button or an Image button. No entanto, emitindo JavaScript do lado do cliente, controles diferentes podem iniciar um evento de postback.However, by emitting client-side JavaScript, different controls can initiate a postback event.

Construtores

PostBackOptions(Control)

Inicializa uma nova instância da classe PostBackOptions com os dados de controle de destino especificados.Initializes a new instance of the PostBackOptions class with the specified target control data.

PostBackOptions(Control, String)

Inicializa uma nova instância da classe PostBackOptions com os dados de argumento e controle de destino especificados.Initializes a new instance of the PostBackOptions class with the specified target control and argument data.

PostBackOptions(Control, String, String, Boolean, Boolean, Boolean, Boolean, Boolean, String)

Inicializa uma nova instância da classe PostBackOptions com os valores especificados para as propriedades da instância.Initializes a new instance of the PostBackOptions class with the specified values for the instance's properties.

Propriedades

ActionUrl

Obtém ou define a URL de destino para o postback de uma página do Web Forms.Gets or sets the target URL for the postback of a Web Forms page.

Argument

Obtém ou define um argumento opcional que é transferido no evento de postback.Gets or sets an optional argument that is transferred in the postback event.

AutoPostBack

Obtém ou define um valor que indica se o formulário postará automaticamente de volta para o servidor em resposta a uma ação do usuário.Gets or sets a value that indicates whether the form will automatically post back to the server in response to a user action.

ClientSubmit

Obtém ou define um valor que indica se o evento de postback deve ocorrer de script do lado do cliente.Gets or sets a value indicating whether the postback event should occur from client-side script.

PerformValidation

Obtém ou define um valor que indica se a validação do lado do cliente é necessária antes que o evento de postback ocorra.Gets or sets a value indicating whether client-side validation is required before the postback event occurs.

RequiresJavaScriptProtocol

Obtém ou define um valor que indica se o prefixo javascript: é gerado para o script do lado do cliente.Gets or sets a value indicating whether the javascript: prefix is generated for the client-side script.

TargetControl

Obtém o destino de controle que recebe o evento de postback.Gets the control target that receives the postback event.

TrackFocus

Obtém ou define um valor que indica se o evento de postback deve retornar a página para a posição de rolagem atual e retornar o foco para o controle atual.Gets or sets a value indicating whether the postback event should return the page to the current scroll position and return focus to the current control.

ValidationGroup

Obtém ou define o grupo de controles para o qual o objeto PostBackOptions causa a validação quando ele executa um postback para o servidor.Gets or sets the group of controls for which the PostBackOptions object causes validation when it posts back to the server.

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Aplica-se a

Confira também