2010-11-18 54 views

回答

13

您可以將javascript添加到按鈕的OnClientClick()事件中...如果您要取消該事件,則鍵將返回false。如果您返回false,則OnClick不會觸發。

<asp:Button id="DeleteButton" runat="server" Text="Delete" 
      OnClick ="delete_clickhandler" 
      OnClientClick="return confirm('Are you sure you want to?');" /> 

或者,你可以調用的方法在JavaScript

<asp:Button id="DeleteButton" runat="server" Text="Delete" 
      OnClick ="delete_clickhandler" 
      OnClientClick="return MyDeleteConfirm();" /> 

凡MyDeleteConfirm()做的更精緻,但如果你不想刪除返回false。

+0

谷歌FTW。保存了我的一天。 – DoStuffZ 2014-01-22 08:37:46

0

這爲我工作(接受的答案沒有)

<asp:Button id="DeleteButton" runat="server" Text="Delete" 
OnClientClick="if (!confirm('Are you sure you want to delete?')) return false;"> 
</asp:Button> 
+1

奇怪的是,我發佈的代碼不適合你...你有什麼_應該比必要更復雜。另外,我的代碼的目的是抑制「OnClick」事件,並且我沒有在您的按鈕上看到一個按鈕......您如何將實際事件連接到此按鈕?想知道這是否與它有關。 – 2016-02-10 08:14:56