ClientScriptManager.GetPostBackEventReference Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Retorna uma cadeia de caracteres que pode ser usada em um evento cliente para causar postback no servidor.
Sobrecargas
| Nome | Description |
|---|---|
| GetPostBackEventReference(Control, String, Boolean) |
Retorna uma cadeia de caracteres a ser usada em um evento cliente para causar postback no servidor. A cadeia de caracteres de referência é definida pelo controle especificado que manipula o postback e um argumento de cadeia de caracteres de informações de evento adicionais. Opcionalmente, registra a referência de evento para validação. |
| GetPostBackEventReference(PostBackOptions, Boolean) |
Retorna uma cadeia de caracteres que pode ser usada em um evento cliente para causar postback no servidor. A cadeia de caracteres de referência é definida pelo objeto especificado PostBackOptions . Opcionalmente, registra a referência de evento para validação. |
| GetPostBackEventReference(PostBackOptions) |
Retorna uma cadeia de caracteres que pode ser usada em um evento cliente para causar postback no servidor. A cadeia de caracteres de referência é definida pela instância especificada PostBackOptions . |
| GetPostBackEventReference(Control, String) |
Retorna uma cadeia de caracteres que pode ser usada em um evento cliente para causar postback no servidor. A cadeia de caracteres de referência é definida pelo controle especificado que manipula o postback e um argumento de cadeia de caracteres de informações de evento adicionais. |
GetPostBackEventReference(Control, String, Boolean)
Retorna uma cadeia de caracteres a ser usada em um evento cliente para causar postback no servidor. A cadeia de caracteres de referência é definida pelo controle especificado que manipula o postback e um argumento de cadeia de caracteres de informações de evento adicionais. Opcionalmente, registra a referência de evento para validação.
public:
System::String ^ GetPostBackEventReference(System::Web::UI::Control ^ control, System::String ^ argument, bool registerForEventValidation);
public string GetPostBackEventReference(System.Web.UI.Control control, string argument, bool registerForEventValidation);
member this.GetPostBackEventReference : System.Web.UI.Control * string * bool -> string
Public Function GetPostBackEventReference (control As Control, argument As String, registerForEventValidation As Boolean) As String
Parâmetros
- argument
- String
Uma cadeia de caracteres de argumentos opcionais a serem passados para control.
- registerForEventValidation
- Boolean
true para registrar a referência de evento para validação; caso contrário, false.
Retornos
Uma cadeia de caracteres que, quando tratada como script no cliente, inicia o postback.
Exceções
O especificado Control é null.
Comentários
Para implementar a IPostBackEventHandler interface para um Page, use a @ Implements diretiva.
O GetPostBackEventReference método pode ser usado com o Button controle quando a UseSubmitBehavior propriedade é false. Nesse cenário, o GetPostBackEventReference método retorna o evento de postback do cliente para o Button controle.
Se registerForEventValidation for true, o GetPostBackEventReference(PostBackOptions, Boolean) método chamará o RegisterForEventValidation(String, String) método para registrar a referência de evento para validação com uma ID de controle exclusiva que representa o controle do cliente que está gerando o evento.
Confira também
- PostBackOptions
- IPostBackEventHandler
- Retornos de chamada do cliente sem postbacks em páginas ASP.NET
Aplica-se a
GetPostBackEventReference(PostBackOptions, Boolean)
Retorna uma cadeia de caracteres que pode ser usada em um evento cliente para causar postback no servidor. A cadeia de caracteres de referência é definida pelo objeto especificado PostBackOptions . Opcionalmente, registra a referência de evento para validação.
public:
System::String ^ GetPostBackEventReference(System::Web::UI::PostBackOptions ^ options, bool registerForEventValidation);
public string GetPostBackEventReference(System.Web.UI.PostBackOptions options, bool registerForEventValidation);
member this.GetPostBackEventReference : System.Web.UI.PostBackOptions * bool -> string
Public Function GetPostBackEventReference (options As PostBackOptions, registerForEventValidation As Boolean) As String
Parâmetros
- options
- PostBackOptions
Um PostBackOptions que define o postback.
- registerForEventValidation
- Boolean
true para registrar a referência de evento para validação; caso contrário, false.
Retornos
Uma cadeia de caracteres que, quando tratada como script no cliente, inicia o postback do cliente.
Exceções
O PostBackOptions é null.
Comentários
Para implementar a IPostBackEventHandler interface de um Page objeto, use a @ Implements diretiva.
O GetPostBackEventReference método pode ser usado com o Button controle quando a UseSubmitBehavior propriedade é false. Nesse cenário, o GetPostBackEventReference método retorna o evento de postback do cliente para o Button controle.
Se registerForEventValidation for true, o GetPostBackEventReference(PostBackOptions, Boolean) método chamará o RegisterForEventValidation(String, String) método para registrar a referência de evento para validação com uma ID de controle exclusiva que representa o controle do cliente que está gerando o evento.
Confira também
- PostBackOptions
- IPostBackEventHandler
- Button
- Retornos de chamada do cliente sem postbacks em páginas ASP.NET
Aplica-se a
GetPostBackEventReference(PostBackOptions)
Retorna uma cadeia de caracteres que pode ser usada em um evento cliente para causar postback no servidor. A cadeia de caracteres de referência é definida pela instância especificada PostBackOptions .
public:
System::String ^ GetPostBackEventReference(System::Web::UI::PostBackOptions ^ options);
public string GetPostBackEventReference(System.Web.UI.PostBackOptions options);
member this.GetPostBackEventReference : System.Web.UI.PostBackOptions -> string
Public Function GetPostBackEventReference (options As PostBackOptions) As String
Parâmetros
- options
- PostBackOptions
Um PostBackOptions que define o postback.
Retornos
Uma cadeia de caracteres que, quando tratada como script no cliente, inicia o postback do cliente.
Exceções
O PostBackOptions parâmetro é null
Comentários
Para implementar a IPostBackEventHandler interface para um Page, use a @ Implements diretiva.
O GetPostBackEventReference método pode ser usado com o Button controle quando a UseSubmitBehavior propriedade é false. Nesse cenário, o GetPostBackEventReference método retorna o evento de postback do cliente para o Button controle.
Confira também
- PostBackOptions
- IPostBackEventHandler
- Button
- Retornos de chamada do cliente sem postbacks em páginas ASP.NET
Aplica-se a
GetPostBackEventReference(Control, String)
Retorna uma cadeia de caracteres que pode ser usada em um evento cliente para causar postback no servidor. A cadeia de caracteres de referência é definida pelo controle especificado que manipula o postback e um argumento de cadeia de caracteres de informações de evento adicionais.
public:
System::String ^ GetPostBackEventReference(System::Web::UI::Control ^ control, System::String ^ argument);
public string GetPostBackEventReference(System.Web.UI.Control control, string argument);
member this.GetPostBackEventReference : System.Web.UI.Control * string -> string
Public Function GetPostBackEventReference (control As Control, argument As String) As String
Parâmetros
- argument
- String
Uma cadeia de caracteres de argumentos opcionais a serem passados para o controle que processa o postback.
Retornos
Uma cadeia de caracteres que, quando tratada como script no cliente, inicia o postback.
Exceções
O especificado Control é null.
Exemplos
O exemplo de código a seguir demonstra o uso do GetPostBackEventReference método. O controle MyControlpersonalizado implementa a IPostBackEventHandler interface. Quando o botão na página é clicado, o RaisePostBackEvent método do controle personalizado é invocado.
<%@ 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">
public class MyControl : Label, IPostBackEventHandler
{
// Use the constructor to defined default label text.
public MyControl()
{
base.Text = "No postback raised.";
}
// Implement the RaisePostBackEvent method from the
// IPostBackEventHandler interface.
public void RaisePostBackEvent(string eventArgument)
{
base.Text = "Postback handled by " + this.ID.ToString() + ". <br/>" +
"Postback caused by " + eventArgument.ToString() + ".";
}
}
protected void Page_Load(object sender, EventArgs e)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Create an instance of the custom label control and
// add it to the page.
MyControl mycontrol = new MyControl();
mycontrol.ID = "mycontrol1";
PlaceHolder1.Controls.Add(mycontrol);
PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
// Create a button element with its onClick attribute defined
// to create a postback event reference to the custom label control.
HtmlInputButton b = new HtmlInputButton();
b.ID = "mybutton1";
b.Value = "Click";
b.Attributes.Add("onclick", cs.GetPostBackEventReference(mycontrol, b.ID.ToString()));
PlaceHolder1.Controls.Add(b);
PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
// Create a link element with its href attribute defined
// to create a postback event reference to the custom label control.
HtmlAnchor a = new HtmlAnchor();
a.ID = "myanchor1";
a.InnerText = "link";
a.HRef = cs.GetPostBackClientHyperlink(mycontrol, a.ID.ToString());
PlaceHolder1.Controls.Add(a);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ClientScriptManager Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder id="PlaceHolder1"
runat="server">
</asp:PlaceHolder>
</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">
Public Class MyControl
Inherits Label
Implements IPostBackEventHandler
Public Sub New()
MyBase.Text = "No postback raised."
End Sub
Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
MyBase.Text = "Postback handled by " & Me.ID.ToString() & ". <br/>" & _
"Postback caused by " + eventArgument.ToString() & "."
End Sub
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Create an instance of the custom label control and
' add it to the page.
Dim mycontrol As New MyControl()
MyControl.ID = "mycontrol1"
PlaceHolder1.Controls.Add(MyControl)
PlaceHolder1.Controls.Add(New LiteralControl("<br/>"))
' Create a button element with its onClick attribute defined
' to create a postback event reference to the custom label control.
Dim b As New HtmlInputButton()
b.ID = "mybutton1"
b.Value = "Click"
b.Attributes.Add("onclick", cs.GetPostBackEventReference(MyControl, b.ID.ToString()))
PlaceHolder1.Controls.Add(b)
PlaceHolder1.Controls.Add(New LiteralControl("<br/>"))
' Create a link element with its href attribute defined
' to create a postback event reference to the custom label control.
Dim a As New HtmlAnchor()
a.ID = "myanchor1"
a.InnerText = "link"
a.HRef = cs.GetPostBackClientHyperlink(MyControl, a.ID.ToString())
PlaceHolder1.Controls.Add(a)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>ClientScriptManager Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder id="PlaceHolder1"
runat="server">
</asp:PlaceHolder>
</div>
</form>
</body>
</html>
O exemplo de código a seguir tem a mesma funcionalidade que a anterior, exceto que, em vez de um controle personalizado, a Page classe implementa a IPostBackEventHandler interface.
<%@ Page Language="C#" %>
<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void RaisePostBackEvent(string eventArgument)
{
Label1.Text = "Postback handled by " + this.ID.ToString() + ". <br/>" +
"Postback caused by " + eventArgument.ToString() + "."; ;
}
protected void Page_Load(object sender, EventArgs e)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Create a button element with its onClick attribute defined
// to create a postback event reference to the custom label control.
HtmlInputButton b = new HtmlInputButton();
b.ID = "mybutton1";
b.Value = "Click";
b.Attributes.Add("onclick", cs.GetPostBackEventReference(this, b.ID.ToString()));
PlaceHolder1.Controls.Add(b);
PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
// Create a link element with its href attribute defined
// to create a postback event reference to the custom label control.
HtmlAnchor a = new HtmlAnchor();
a.ID = "myanchor1";
a.InnerText = "link";
a.HRef = cs.GetPostBackClientHyperlink(this, a.ID.ToString());
PlaceHolder1.Controls.Add(a);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ClientScriptManager Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label id="Label1"
runat="server" />
<br />
<asp:PlaceHolder id="PlaceHolder1"
runat="server">
</asp:PlaceHolder>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public Sub RaisePostBackEvent(ByVal eventArgument As String) _
Implements IPostBackEventHandler.RaisePostBackEvent
Label1.Text = "Postback handled by " & Me.ID.ToString() & ". <br/>" & _
"Postback caused by " + eventArgument.ToString() & "."
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Create a button element with its onClick attribute defined
' to create a postback event reference to the custom label control.
Dim b As New HtmlInputButton()
b.ID = "mybutton1"
b.Value = "Click"
b.Attributes.Add("onclick", cs.GetPostBackEventReference(Me, b.ID.ToString()))
PlaceHolder1.Controls.Add(b)
PlaceHolder1.Controls.Add(New LiteralControl("<br/>"))
' Create a link element with its href attribute defined
' to create a postback event reference to the custom label control.
Dim a As New HtmlAnchor()
a.ID = "myanchor1"
a.InnerText = "link"
a.HRef = cs.GetPostBackClientHyperlink(Me, a.ID.ToString())
PlaceHolder1.Controls.Add(a)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ClientScriptManager Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label id="Label1"
runat="server" />
<br />
<asp:PlaceHolder id="PlaceHolder1"
runat="server">
</asp:PlaceHolder>
</div>
</form>
</body>
</html>
Comentários
Para implementar a IPostBackEventHandler interface para um Page, use a @ Implements diretiva.
O GetPostBackEventReference método pode ser usado com o Button controle quando a UseSubmitBehavior propriedade é false. Nesse cenário, o GetPostBackEventReference método retorna o evento de postback do cliente para o Button controle.
Confira também
- PostBackOptions
- IPostBackEventHandler
- Retornos de chamada do cliente sem postbacks em páginas ASP.NET