IPostBackEventHandler.RaisePostBackEvent メソッド
アセンブリ: System.Web (system.web.dll 内)
構文
Dim instance As IPostBackEventHandler Dim eventArgument As String instance.RaisePostBackEvent(eventArgument)
IPostBackEventHandler インターフェイスを実装しているコントロールの RaisePostBackEvent メソッドに、ページが eventArgument パラメータの値を渡します。このコントロールには、ポストバックを発生させる HTML 要素も表示されます。このコントロールにポストバックのクライアント側スクリプトが表示されている場合、eventArgument パラメータにこのスクリプトからの引数が渡されます。送信によってポストバックが発生した場合、eventArgument パラメータは null 参照 (Visual Basic では Nothing) です。
このメソッドは、HTML サーバー コントロールおよび Web サーバー コントロールによって実装される多くのイベントを処理する機能を提供します。
ポストバックを発生させるカスタム ボタン サーバー コントロールを定義し、RaisePostBackEvent メソッドを使用してポストバック イベントをキャプチャして、サーバーで Click イベントを発生させるコード例を次に示します。
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' />"); } } }
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- IPostBackEventHandler.RaisePostBackEvent メソッドのページへのリンク