Export (0) Print
Expand All

IPostBackEventHandler.RaisePostBackEvent Method

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

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

void RaisePostBackEvent(
	string eventArgument
)

Parameters

eventArgument
Type: System.String

A String that represents an optional event argument to be passed to the event handler.

The page passes the value of the eventArgument parameter to the RaisePostBackEvent method of the control that implements the IPostBackEventHandler interface. This control also renders the HTML element that causes the postback to occur. If the control renders client-side script for postback, the argument from the script is passed in the eventArgument parameter. If the postback is caused by a simple submit operation, the eventArgument parameter is null.

This method provides the functionality for many events implemented by HTML and Web server controls.

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

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.0

Community Additions

ADD
Show:
© 2014 Microsoft