I have a LinkButton
that executes on the server and changes the page. Historically, I've had a confirm
message box that executes OnClientClick
to ensure the user would like to navigate away.
So far it looks like this:
ASP.NET:
<!-- language: lang-html --><asp:LinkButton runat="server" ID="ChangePage" Text="Change page"
OnClientClick="confirm('are you sure you want to change page?');"
OnClick="Navigate" >
Change Page
</asp:LinkButton>
HTML Output:
<!-- language: lang-html --><a id="MainContent_ChangePage"
onclick="confirm('are you sure you want to change page?');"
href="javascript:__doPostBack('ctl00$MainContent$ChangePage','')" >
Change page
</a>
This all works fine like this. The trouble is that I'm trying to replace all confirm boxes with a prettier jQuery-UI implementation like this:
<!-- language: lang-js -->window.confirm = function (message, obj) {
$('<div/>')
.attr({ title: 'Webpage Confirm'})
.html(message)
.dialog({
resizable: false,
modal: true,
width: 500,
buttons: {
"OK": function () {
__doPostBack(obj, '');
$(this).dialog('close');
return true;
},
"Cancel": function () {
$(this).dialog('close');
return false;
}
}
});
};
I believe this has to do with the fact that the confirm
dialog operates synchronously, while jQuery dialogs occur asynchronously. However, I thought setting modal: true
would cause it to wait for a response.
How can I override window.confirm
to get consistent behavior?