I have a LinkButton
where I use the OnClientClick
property to ask the user whether he really wants to perform an action, e.g:
<script>
function confirmDelete() {
return confirm('Do you really want to delete?');
}
</script>
<asp:LinkButton runat="server" OnClientClick="return confirmDelete()" ... />
This pattern usually works, but on this specific page, it doesn't. No matter whether I click OK or Cancel in the confirm dialog, the postback is executed.
Just for completeness (to answer pst's question): the rendered HTML is OK. E.g. it looks like this:
<a id="ctl00_c1_content_btnDelete" onclick="return confirmDelete();"
href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(..))"
... >
Delete
</a>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…