System.Web.UI Namespace


.NET Framework Class Library
IPostBackEventHandler Interface

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

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
Syntax

Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Interface IPostBackEventHandler
Visual Basic (Usage)
Dim instance As IPostBackEventHandler
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public interface IPostBackEventHandler
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public interface class IPostBackEventHandler
JScript
public interface IPostBackEventHandler
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 Pages.

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.

Visual Basic
Imports System
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

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

.NET Framework Security

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Other Resources

Tags :


Community Content

Tim Babamuratov
User Control inside a Repeater

Spent 3 hours trying to figure out why controls inside a Repeater template would not raise events. Felt like events just never reached my child controls. Inspected form parameters and there was information with the client ids of Repeater's child controls.

Cause: was binding the Repeater in PreRender()
Solution: moved binding of Repeater to Page_Load to enable event processing by child

controls.

Hope this will help someone else.
Tags :

Tim Babamuratov
Child controls inside the Repeater and similar controls

Spent 3 hours trying to figure out why controls inside a Repeater template would not raise events. Felt like events just never reached my child controls (which implemented IPostBackEventHander). Inspected page Form parameters and there was the information with the client ids of Repeater's child controls upon each event. The Repeater was in UpdatePanel, so I thought it has something to do with it.

Cause: was binding the Repeater in OnPreRender().
Solution: moved binding of Repeater to Page_Load, which enabled normal event processing by child controls.

Hope this will help someone else.


Page view tracker