Control.RaiseBubbleEvent(Object, EventArgs) Control.RaiseBubbleEvent(Object, EventArgs) Control.RaiseBubbleEvent(Object, EventArgs) Control.RaiseBubbleEvent(Object, EventArgs) Method

定義

指派事件的任何來源和它的資訊至控制項的父控制項。Assigns any sources of the event and its information to the control's parent.

protected:
 void RaiseBubbleEvent(System::Object ^ source, EventArgs ^ args);
protected void RaiseBubbleEvent (object source, EventArgs args);
member this.RaiseBubbleEvent : obj * EventArgs -> unit
Protected Sub RaiseBubbleEvent (source As Object, args As EventArgs)

參數

source
Object Object Object Object

事件的來源。The source of the event.

args
EventArgs EventArgs EventArgs EventArgs

包含事件資料的 EventArgs 物件。An EventArgs object that contains the event data.

範例

下列程式碼範例示範如何建立自ChildControl定義類別,並覆Button.OnClick寫方法以呼叫RaiseBubbleEventButton.Click事件傳送至其父 ASP.NET 伺服器控制項的方法。The following code example demonstrate how to create a custom class, ChildControl, overriding the Button.OnClick method to call the RaiseBubbleEvent method that sends the Button.Click event to its parent ASP.NET server control. 當使用者在包含實例的ChildControlASP.NET 網頁中按一下按鈕時,它會在包含實例ChildControlOnBubbleEvent父控制項上引發方法,並寫入字串「ChildControl 類別 OnClick 方法為呼叫至頁面。When the user clicks a button in an ASP.NET page that includes an instance of ChildControl, it raises the OnBubbleEvent method on the parent control that contains the instance of ChildControl and writes the string "The ChildControl class OnClick method is called" to the page.

public class ChildControl : Button
{
   [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
   protected override void OnClick(EventArgs e) 
   {
      base.OnClick(e);
      Context.Response.Write("<br><br>ChildControl's OnClick called.");
      // Bubble this event to parent.
      RaiseBubbleEvent(this, e);
   }
Public Class ChildControl
   Inherits Button
   
   <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
   Protected Overrides Sub OnClick(e As EventArgs)
      MyBase.OnClick(e)
      Context.Response.Write("<br><br>ChildControl's OnClick called.")
      ' Bubble this event to parent.
      RaiseBubbleEvent(Me, e)
   End Sub
End Class

備註

ASP.NET 伺服器控制項(例如Repeater、和DataList GridView Web 控制項)可以包含引發事件的子控制項。ASP.NET server controls such as the Repeater, DataList and GridView Web controls can contain child controls that raise events. 例如, GridView控制項中的每個資料列都可以包含一個或多個由範本動態建立的按鈕。For example, each row in a GridView control can contain one or more buttons created dynamically by templates. 來自嵌套控制項的事件是「反升」,而不是個別引發事件的每個按鈕,也就是將它們傳送至控制項的父系。Rather than each button raising an event individually, events from the nested controls are "bubbled" - that is, they are sent to the control's parent. 父代會輪流引發名RowCommand為且具有參數值的泛型事件。The parent in turn raises a generic event called RowCommand with parameter values. 這些值可讓您判斷引發原始事件的個別控制項。These values allow you to determine which individual control that raised the original event. 藉由回應這個單一事件,您可以避免為子控制項撰寫個別事件處理方法。By responding to this single event, you can avoid having to write individual event-handling methods for child controls.

當您無法覆寫這個方法時,您的作者可以藉由覆寫OnBubbleEvent方法來處理或引發反升事件。While you cannot override this method, controls you author can handle or raise bubbled events by overriding the OnBubbleEvent method.

適用於

另請參閱