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 與網頁伺服器控制項實作的事件功能。