IPostBackEventHandler.RaisePostBackEvent(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当由类实现时,使服务器控件能够处理将窗体发送到服务器时引发的事件。
public:
void RaisePostBackEvent(System::String ^ eventArgument);
public void RaisePostBackEvent(string eventArgument);
abstract member RaisePostBackEvent : string -> unit
Public Sub RaisePostBackEvent (eventArgument As String)
参数
示例
下面的代码示例定义一个自定义按钮服务器控件,该控件会导致回发,使用 RaisePostBackEvent 方法捕获回发事件,并在服务器上引发事件 Click 。
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' />");
}
}
}
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
注解
页面将 参数的值 eventArgument 传递给 RaisePostBackEvent 实现 IPostBackEventHandler 接口的控件的 方法。 此控件还呈现导致回发的 HTML 元素。 如果 控件呈现用于回发的客户端脚本,则脚本中的 参数将传递到 参数 eventArgument 中。 如果回发是由简单的提交操作引起的,则 eventArgument 参数为 null。
此方法为 HTML 和 Web 服务器控件实现的许多事件提供功能。