0

I have the following code:

<asp:Button ID="btnHideDep" runat="server" Text="Remove this institution" CssClass="link1 small" OnClientClick="return confirm('Confirm remove?');" OnClick="btnHideDep_Click"/>

This button does not fire btnHideDep_Click when OK is pressed in the confirm box. More interestingly, if i have OnClientClick=return true; the method btnHideDep_Click is still not fired. Also just to confirm, without the property OnClientclick, btnHideDep_Click is fired properly.

I read a few posts about this and it seems like this should work. So I must be missing something very basic here...

Andrei
  • 42,814
  • 35
  • 154
  • 218
Greg
  • 640
  • 5
  • 11
  • 23
  • Possible duplicate of [OnclientClick and OnClick is not working at the same time?](http://stackoverflow.com/questions/2155048/onclientclick-and-onclick-is-not-working-at-the-same-time) – Alex Dec 22 '15 at 15:44
  • Perhaps [this answer](http://stackoverflow.com/a/9484887/2096401) is relevant? – TripeHound Dec 22 '15 at 15:44

1 Answers1

2

Try

OnClientClick="if (!confirm('Confirm remove?')) return false;"
Andrei
  • 42,814
  • 35
  • 154
  • 218
  • The links above seem to do this: roughly, returning `true` says "I've handled it" so the `onClick` isn't invoked. – TripeHound Dec 23 '15 at 13:45