2016-05-17 131 views
0

我有以下代碼。我需要有一個確認,然後在服務器上刪除..如果我有OnClick它不會觸發。任何想法?OnClick不會觸發OnClientClick

<asp:Button ID="btnDelete" runat="server" Text="Delete Report" OnClientClick="return confirm ('This will delete the report. Continue?');" OnClick="btnDelete_Click" /> 


protected void btnDelete_Click(object sender, EventArgs e) 
{ 
    // I have code here but it never fires 

} 
+0

我認爲最好在btnDelete_Click(...)方法下添加確認消息,而不是將其添加到OnClientClick上。 – Auguste

+0

如果點擊事件中沒有任何代碼正在運行,您是否查看了源代碼以確保按鈕ID未更改?除非你將其聲明爲靜態,否則Asp.Net會預先設置爲按鈕ID。ClientIDMode =「Static」 – dinotom

回答

0

add「return false;」在OnClick之後。

<asp:Button ID="btnDelete" runat="server" Text="Delete Report" OnClientClick="return confirm ('This will delete the report. Continue?'); return false; " OnClick="btnDelete_Click" />