简体   繁体   中英

Response.write(script) is not working.

I'm writing a program in ASP.NET with a VB backend. I am trying to get a popup window to open using javascript prior to a subroutine running, and close it when the routine ends as a way to provide a progress indicator to the user, as some of these subroutine calls can take a few minutes.

My code is below.

    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>")

However, I never see a popup, but I am pretty sure the javascript is correct. What is going wrong?

Simple example.

<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" />

The JavaScript function will execute. Then when it's done executing, the page will begin the postback to the server.

From server side, you could use RegisterClientStartupScript to display an alert message when it's done. But plain JavaScript alert boxes suck. They demand the user's attention and can't be styled.

Instead of using an alert, just show an indeterminate progress bar or a label that says "Loading...". Once the postback completes, that can go away. Or you could use a notification library such as Noty to display a loading message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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