Button.IPostBackEventHandler.RaisePostBackEvent(String) Methode

Definition

Löst Ereignisse für das Button-Steuerelement aus, wenn es ein Postback an den Server ausführt.

 virtual void System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(System::String ^ eventArgument) = System::Web::UI::IPostBackEventHandler::RaisePostBackEvent;
void IPostBackEventHandler.RaisePostBackEvent (string eventArgument);
abstract member System.Web.UI.IPostBackEventHandler.RaisePostBackEvent : string -> unit
override this.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent : string -> unit
Sub RaisePostBackEvent (eventArgument As String) Implements IPostBackEventHandler.RaisePostBackEvent

Parameter

eventArgument
String

Das Argument für das Ereignis.

Implementiert

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die IPostBackEventHandler.RaisePostBackEvent -Methode überschrieben wird, sodass das -Ereignis immer in einem benutzerdefinierten Button Steuerelement ausgelöst OnClick wird.

namespace Samples.AspNet.CS.Controls
{
  [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
  public class CustomButtonRaisePostBackEvent : System.Web.UI.WebControls.Button, System.Web.UI.IPostBackEventHandler
  {
    private string message = System.String.Empty;

    protected override void Render(System.Web.UI.HtmlTextWriter writer) 
    {
      // Render a HTML submit button.
      writer.Write("<INPUT TYPE='submit' name='" + this.UniqueID + "' value='Click Me' />"); 
      writer.Write("<BR>" + message);
    }
    
    // Re-implement the IPostBackEventHandler's RaisePostBackEvent method.
    // Note: C# allows this, where VB.NET does not.
    public void RaisePostBackEvent(System.String eventArgument)
    {
      // Raise the Click event of the custom Button web control.
      OnClick(new System.EventArgs());

      // Don't call the Page.Validate or OnCommand events,
      // which the base IPostBackEventHandler's RaisePostBackEvent method does.
    }

    protected override void OnClick(System.EventArgs e)
    {
      message = "RaisePostBackEvent method successful!";
    }
  }
}
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Public Class CustomButtonRaisePostBackEvent
    Inherits System.Web.UI.WebControls.Button

    Private message As String = System.String.Empty

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        ' Render a HTML submit button.
        writer.Write("<INPUT TYPE='submit' name='" + Me.UniqueID + "' value='Click Me' />")
        writer.Write("<BR>" + message)
    End Sub

    ' Note: VB.NET does not allow one to re-implement a base class interface, whereas C# does.
    ' Hence, just use the base class's PostBackEventHandler's RaisePostBackEvent method,
    ' which calls the OnClick method.

    Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
        message = "RaisePostBackEvent method successful!"
    End Sub
End Class

Hinweise

Dieses Ereignis wird intern vom Button Steuerelement verwendet, wenn darauf geklickt wird, um ein Ereignis und, Click falls definiert, ein Command Ereignis auszulösen.

Gilt für:

Weitere Informationen