Greg
Greg

Reputation: 648

C# .NET OnClientClick returning true but OnClick not firing

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...

Upvotes: 0

Views: 878

Answers (1)

Andrei
Andrei

Reputation: 44620

Try

OnClientClick="if (!confirm('Confirm remove?')) return false;"

Upvotes: 2

Related Questions