一個按鈕觸發兩個事件可以嗎?
問:
我想讓一個按鈕觸發兩個事件,submit1_click 和submit2_click()可以嗎?怎麼設?先執行submit1_click,再接著執行submit2_click。是再OnClick裡設還是submit1_click裡呼叫submit2_click呀?(用c#編輯)
______________________________________________________________________________________________
答1:
可以
button1.Click += new System.EventHandler( this.submit1_click );
button1.Click += new System.EventHandler( this.submit2_click );
______________________________________________________________________________________________
答2:
up
______________________________________________________________________________________________
答3:
只要能觸發就好處理了,哪怕是N個事件頁能通過自己的程式程式碼來實現!
______________________________________________________________________________________________
答4:
事件是一個特殊的組播代表,而組播代表的特點就是可以註冊多個事件處理程式
______________________________________________________________________________________________
答5:
你也可以採用,在事件1中啟用事件2的方法來處理
______________________________________________________________________________________________
答6:
這樣
submit1.Click += new System.EventHandler( this.submit1_click );
submit1.Click += new System.EventHandler( this.submit2_click );
______________________________________________________________________________________________
答7:
<asp:button id="submit1" OnClick+=new System.EventHandler(this.submit1_click) OnClick+=new System.EventHandler(this.Submit2_click) runat="server"/>
這樣寫錯在那裡呀,顯示的錯誤是:伺服器標記的格式不正確.
程式碼還需要在其他地方宣告 EventHandler嗎?
______________________________________________________________________________________________
答8:
放到系統初始化的那段程式碼裡
______________________________________________________________________________________________
答9:
詳細說說好嗎?
______________________________________________________________________________________________
答10:
private void InitializeComponent()
{
submit1.Click += new System.EventHandler( this.submit1_click );
submit1.Click += new System.EventHandler( this.submit2_click );
}
______________________________________________________________________________________________
答11:
不行呀,submit1受保護級別限制
______________________________________________________________________________________________
答12:
可以,void 返回值的可以進行多路委託。
______________________________________________________________________________________________
答13:
學習
______________________________________________________________________________________________
答14:
不如在一個按鈕的事件中加入對另一個事件的觸發