IPostBackEventHandler.RaisePostBackEvent(String) IPostBackEventHandler.RaisePostBackEvent(String) IPostBackEventHandler.RaisePostBackEvent(String) IPostBackEventHandler.RaisePostBackEvent(String) Method

Definizione

Quando viene implementato da una classe, consente a un controllo server di elaborare un evento generato quando si invia un form al server.When implemented by a class, enables a server control to process an event raised when a form is posted to the server.

public:
 void RaisePostBackEvent(System::String ^ eventArgument);
public void RaisePostBackEvent (string eventArgument);
abstract member RaisePostBackEvent : string -> unit
Public Sub RaisePostBackEvent (eventArgument As String)

Parametri

eventArgument
String String String String

String che rappresenta un argomento di evento facoltativo da passare al gestore eventi.A String that represents an optional event argument to be passed to the event handler.

Esempi

Nell'esempio di codice seguente viene definito un controllo server Button personalizzato che provoca il postback, acquisisce l'evento RaisePostBackEvent di postback utilizzando il metodo Click e genera un evento sul server.The following code example defines a custom button server control that causes postback, captures the postback event using the RaisePostBackEvent method, and raises a Click event on the server.

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

Commenti

La pagina passa il valore del eventArgument parametro RaisePostBackEvent al metodo del controllo che implementa l' IPostBackEventHandler interfaccia.The page passes the value of the eventArgument parameter to the RaisePostBackEvent method of the control that implements the IPostBackEventHandler interface. Questo controllo esegue anche il rendering dell'elemento HTML che causa il postback.This control also renders the HTML element that causes the postback to occur. Se il controllo esegue il rendering dello script lato client per il postback, l'argomento dello script viene passato nel eventArgument parametro.If the control renders client-side script for postback, the argument from the script is passed in the eventArgument parameter. Se il postback è causato da un'operazione di invio semplice, eventArgument il parametro nullè.If the postback is caused by a simple submit operation, the eventArgument parameter is null.

Questo metodo fornisce la funzionalità per molti eventi implementati da controlli server HTML e Web.This method provides the functionality for many events implemented by HTML and Web server controls.

Si applica a

Vedi anche