IPostBackEventHandler Interface
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Define o método que os controlos do servidor ASP.NET devem implementar para gerir eventos de postback.
public interface class IPostBackEventHandler
public interface IPostBackEventHandler
type IPostBackEventHandler = interface
Public Interface IPostBackEventHandler
- Derivado
Exemplos
O exemplo de código seguinte define um controlo personalizado de servidor de botões que causa postback, captura o evento de postback usando o RaisePostBackEvent método e gera um Click evento no servidor.
using System;
using System.Web.UI;
using System.Collections;
using System.Collections.Specialized;
namespace CustomControls {
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
public class MyButton: Control, IPostBackEventHandler {
// Defines the Click event.
public event EventHandler Click;
//Invoke delegates registered with the Click event.
protected virtual void OnClick(EventArgs e) {
if (Click != null) {
Click(this, e);
}
}
// Define the method of IPostBackEventHandler that raises change events.
public void RaisePostBackEvent(string eventArgument){
OnClick(new EventArgs());
}
protected override void Render(HtmlTextWriter output) {
output.Write("<INPUT TYPE = submit name = " + this.UniqueID +
" Value = 'Click Me' />");
}
}
}
Imports System.Web.UI
Imports System.Collections
Imports System.Collections.Specialized
Namespace CustomControls
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> Public Class MyButton
Inherits Control
Implements IPostBackEventHandler
' Define the Click event.
Public Event Click As EventHandler
' Invoke delegates registered with the Click event.
Protected Overridable Sub OnClick(e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
' Define the method of IPostBackEventHandler that raises change events.
Public Sub RaisePostBackEvent(eventArgument As String) _
Implements IPostBackEventHandler.RaisePostBackEvent
OnClick(New EventArgs())
End Sub
Protected Overrides Sub Render(output As HtmlTextWriter)
output.Write("<INPUT TYPE = submit name = " & Me.UniqueID & _
" Value = 'Click Me' />")
End Sub
End Class
End Namespace
Observações
Para criar um controlo de servidor que capture informações de submissão de formulários do navegador, deve implementar esta interface. Para mais informações sobre como usar esta interface, consulte Server Event Handling em ASP.NET Web Forms Pages.
Métodos
| Name | Description |
|---|---|
| RaisePostBackEvent(String) |
Quando implementado por uma classe, permite que um controlo de servidor processe um evento gerado quando um formulário é publicado no servidor. |