OnClientClick in an asp:LinkButton - using confirm() doesn't work inevery browser

D

dddan

Here's my code:

<asp:LinkButton
OnClick="DeleteFile"
OnClientClick="if (!confirm ('Are you certain you want to delete
this file?') ) return false;"
runat="server"
ID="DeleteButton">DELETE
</asp:LinkButton>

Now, this works fine in FireFox but in IE7 on Vista it deletes the
file whether the user hits OK or Cancel. Any guidance/ideas?

Thanks!
 
B

bruce barker

there is a long standing IE bug (since 5.5) where returning false doesn't
cancel the event as it should.

function cancelEvent()
{
// ie hack
if (window.event) window.event.cancelBubble = true;
return false;
}

<asp:LinkButton
OnClick="DeleteFile"
OnClientClick="if (!confirm ('Are you certain you want to delete
this file?') ) return cancelEvent();"
runat="server"
ID="DeleteButton">DELETE
</asp:LinkButton>


-- bruce (sqlwork.com)
 
D

David C

I use this kind of thing very often and have never had a problem with IE6 or
IE7. The only difference is I create a separate confirmdel() Javascript
function and use something like this.

function confirmdel(deltype)
{
if (window.confirm('Are you sure you want to delete this ' + deltype
+ '?') == false)
{
return false;
}
}

On the LinkButton I use OnClientClick="return confirmdel('file');"

HTH
David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top