Edit

Share via


IPostBackEventHandler Interface

Definition

Defines the method ASP.NET server controls must implement to handle postback events.

C#
public interface IPostBackEventHandler
Derived

Examples

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.

C#
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' />");
      }
   }
}

Remarks

To create a server control that captures form submission information from the browser, you must implement this interface. For more information on how to use this interface, see Server Event Handling in ASP.NET Web Forms Pages.

Methods

RaisePostBackEvent(String)

When implemented by a class, enables a server control to process an event raised when a form is posted to the server.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also