0

I have the following code. I need to have a confirmation and then delete on server.. If I have the OnClick it does not fire. Any idea?

 <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

 }
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
  • I think it's better to add the confirmation message under the btnDelete_Click(...) method instead of adding it on the OnClientClick. – Auguste May 17 '16 at 19:11
  • If none of the code in the click event is running, have you viewed the source to ensure the button Id isn't changing? Asp.Net prepends to the button id unless you declare it as static....ClientIDMode="Static" – dinotom May 17 '16 at 19:14

1 Answers1

0

add "return false;" after OnClick.

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