IPostBackEventHandler.RaisePostBackEvent Method (String)

 

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)

Sub RaisePostBackEvent (
	eventArgument As String
)

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.

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

.NET Framework
Available since 1.1
Return to top
Show: