简体   繁体   English

弹出警告框时,背景变为空白

[英]when alert box is poped up,background goes blank

Calling from this page:

`**contact.aspx**`

protected void Page_Load(object sender, EventArgs e) ``{ protected void Page_Load(object sender, EventArgs e) ``{ ctrlWebMessage=WebApplication1.About; ctrlWebMessage=WebApplication1.关于; ctrlWebMessage.Show(this.Page, "Please enter my name"); ctrlWebMessage.Show(this.Page, "请输入我的名字"); }``` }```

about.aspx.cs - ```public void Show(System.Web.UI.Page page, string strMessage) { about.aspx.cs - ```public void Show(System.Web.UI.Page page, string strMessage) {

    page.ClientScript.RegisterStartupScript(page.GetType(), "PopUp", "<script>showDialogModal('MMF Portal', '" + strTmp + "')</script>");
}```

about.aspx function showDialogModal(message) { var confirm = window.alert(message) if (confirm) { return "Yes"; `enter code here` } else { `enter code here` return "No"; } } about.aspx function showDialogModal(message) { var confirm = window.alert(message) if (confirm) { return "Yes"; `enter code here` } else { `enter code here` return "No"; } } function showDialogModal(message) { var confirm = window.alert(message) if (confirm) { return "Yes"; `enter code here` } else { `enter code here` return "No"; } }

Well, the background does not go blank, it NEVER displays (and that is a significant different issue).好吧,背景不会变成空白,它永远不会显示(这是一个显着不同的问题)。 When you click ok on that dialog box, then the rest of the page does display, right?当您在该对话框上单击“确定”时,页面的其余部分会显示,对吗?

So, I would consider adopting some kind of toast message, or some kind of non blocking message box.所以,我会考虑采用某种 toast 消息,或者某种非阻塞消息框。

So, if that alert() is the first thing to display then it does display, and thus the result of the page is halted from display.因此,如果 alert() 是首先显示的内容,那么它确实会显示,因此页面的结果会停止显示。

So, you need to use a dailog that is non blocking (jquery.UI) is really nice.因此,您需要使用非阻塞的 dailog (jquery.UI) 非常好。

Remember full page post back, run your code behind and then inject a alert dialog.记住整页回发,在后面运行您的代码,然后注入一个警报对话框。 Now, code behind is done, and WHOLE page goes back to client, it loads into the browser, and first thing that runs is the alert script (so, page looks blank - it just not had a chance to re-plot).现在,后面的代码完成了,整个页面返回到客户端,它加载到浏览器中,首先运行的是警报脚本(因此,页面看起来是空白的 - 它只是没有机会重新绘制)。

You can as a quick workaround put in a delay before the alert() is to pop up.作为一种快速的解决方法,您可以在 alert() 弹出之前延迟。

Say, like this:说,像这样:

 string myscript 
    = "setTimeout(function() { alert('Hello to world')}, 500)";

 Page.ClientScript.RegisterStartupScript(Page.GetType(), "MyPop", myscript, true);

So above will work, but I suggest you consider a jquery.UI dialog - it will work since they are async in nature.所以上面会起作用,但我建议你考虑一个 jquery.UI 对话框——它会起作用,因为它们本质上是异步的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM