SantLev
SantLev

Reputation: 160

How to make a confirm for onclick event in asp.net?

I have this button in my view:

  <input type="image" name="Command" onclick="CallBtn('SConform')" value="SConform" src='../Images/conform.png' style="float: left;"/>

which calls an action on the controller but i need to add a js confirm window and make it either go ahead with the call if true, or do nothing if false. Does anybody know how could I do it?

Thanks in advance

Upvotes: 0

Views: 474

Answers (2)

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

Try inline confirm dialog like following :

<input type="image" name="Command" onclick="if(confirm('Are you sure ?')) { CallBtn('SConform') }">

Example HERE.

Hope this helps.

Upvotes: 1

fdomn-m
fdomn-m

Reputation: 28611

You can use confirm, it's not pretty though:

function CallBtn(id) {
    if (!confirm("Are you sure?") return;
    ... rest of existing code...

if you're using jquery or bootstrap then there's nicer options.

Upvotes: 1

Related Questions