Defines the method ASP.NET server controls must implement to handle postback events.
Assembly: System.Web (in System.Web.dll)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public Interface IPostBackEventHandler
Dim instance As IPostBackEventHandler
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public interface IPostBackEventHandler
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] public interface class IPostBackEventHandler
public interface IPostBackEventHandler
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.
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.
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
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' />"); } } }
-
AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
-
AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
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.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0Reference
Other Resources
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.
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
Hope this will help someone else.