2012-03-06 336 views

回答

0

好了,你可以把同一個事件兩個按鈕,這樣的事情:

<asp:Button ID="btn1" runat="server" Text="Button 1" CommandName="Save" /> 
<asp:Button ID="btn2" runat="server" Text="Button 2" CommandName="Cancel" /> 

,並在後面的代碼(vb.net):

Protected Sub btn_event(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click, btn2.Click 

    Dim btn As Button = CType(sender, Button) 

    'now you have the button instance on sender object, and you can check the ID property or CommandName property do solve what you want to do! 

End Sub 

C#代碼:

protected void btn_event(object sender, EventArgs e) { 

    Button btn = (Button)sender; 

    //now you have the button instance on sender object, and you can check the ID property or CommandName property do solve what you want to do! 

} 

如果您使用的是C#,請記得在asp:button標籤上設置事件。

+0

謝謝你,先生,我現在正在工作..我第一次抱歉沒有得到它。新手在這裏。 – 2012-03-06 17:25:09