Response.write(script) is not working.

Response.write(script) is not working.

本文关键字:is not working script write Response      更新时间:2023-09-26

我正在用ASP编写程序。. NET和VB后端。我试图得到一个弹出窗口打开使用javascript之前的子程序运行,并关闭它时,例程结束作为一种方式,以提供一个进度指标给用户,因为一些这些子程序调用可以采取几分钟。

我的代码如下。

    Response.Write("<script type='text/javascript'>function openWin() {myWindow = window.open('Status.aspx?FileName=" & gstrCurrentFile & "&FileNumber=" & gCurrentItem & "&Total=" & gTotal & "', 'Status', 'width=200, height=100');};</script>")
    RunOACW2()
    Response.Write("<script type='text/javascript'>function closeWin() {myWindow.close();}</script>")

然而,我从来没有看到一个弹出窗口,但我很确定javascript是正确的。出了什么问题?

简单的例子。

<script type="text/javascript">
function ShowAlertMessage()
{
alert("button clicked"); //instead of alert, you should do something else. alert stops the whole JavaScript execution, but it's good enough for example purposes.
}
</script>
<asp:Button id="Btn1" Text="Click me!" OnClientClick="ShowAlertMessage();" OnClick="Btn1_Click" />

将执行JavaScript函数。然后,当它完成执行时,该页将开始回发到服务器。

在服务器端,您可以使用RegisterClientStartupScript在完成时显示警告消息。但是普通的JavaScript警告框很糟糕。它们需要用户的注意力,不能被设计。

不使用警告,只显示一个不确定的进度条或一个标签,说"Loading…"。一旦回发完成,这种情况就会消失。或者您可以使用通知库(如Noty)来显示加载消息。