My master web page contain JS code to override standard alerts with custom jQuery dialog boxes.
<script type="text/javascript" language="javascript">
window.alert=function(alertMessage)
{
$.msgbox(alertMessage, {type: "info"});
}
</script>
In default.aspx web page onLoad method I am trying to register and display alert script
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "InvalidPassword",
"alert(\"Your login attempt was not successful. Please try again.\");",
true);
Unfortunately it does not work. If I remove JS code which override alert box everything works fine, alert box appears. The override JS is correct, it is working fine if I execute alert js in client side, but it does not work if I try to execute code from server side.
Could anyone explain where is the problem?
I get the same problem when I try to run it from the page_load event of the aspx page, but when I run it from the body onload event it works. I think this is happening because the page_load event occurs before your window.alert override has a chance to be run.
Try this in the body tag:
And the jQuery:
I used the jQuery UI dialog plugin by the way.