的RegisterClientScriptBlock混乱 [英] RegisterClientScriptBlock confusion
问题描述
我的主网页包含JS code覆盖标准警报的自定义的jQuery的对话框。
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>
在Default.aspx的网页的onLoad方法,我尝试注册并显示警告脚本
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);
不幸的是它不工作。如果我删除JS code这覆盖警告框,一切工作正常,会出现警告框。覆盖JS是正确的,它工作正常,如果我在执行客户端警惕JS,但如果我尝试从服务器端执行code这是行不通的。
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?
推荐答案
我得到同样的问题,当我尝试从aspx页面的Page_Load事件中运行它,但是当我从身体的onload事件中运行它,它的工作原理。我认为这正在发生,因为在你的window.alert覆盖有要运行的机会发生在Page_Load事件。
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.
试试这个在身体标记:
<body onload="alert('Your login attempt was not successful. Please try again.');">
和jQuery的:
$(function () {
window.alert = function (message) {
$('#dialog').text(message).dialog();
}
});
我的方式使用jQuery UI的对话框插件。
I used the jQuery UI dialog plugin by the way.
这篇关于的RegisterClientScriptBlock混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!