ClientScript.RegisterStartupScript pause execution rest of the code until close window

2.1k Views Asked by At

I'm using

ClientScript.RegisterStartupScript(this.GetType(), "pop", newWin, true); 

to open popup windows.

I have some code lines after this line. But I need to execute those code after closing the popup. Not immediately.
Any solution?

Button Click event:

 private void button_Click(object sender, EventArgs e)
        {

            string queryString = "WebForm2.aspx";
            string newWin = "window.open('" + queryString + "');";

            ClientScript.RegisterStartupScript(this.GetType(), "pop", newWin, true);

                ((Button)sender).Enabled = false;

        }

Button click Opens pop up page.

1

There are 1 best solutions below

5
On

You can use OnClientClick like this:-

<asp:Button ID="btnSave" runat="server" Text="Save"
    OnClientClick="javascript:return myFunction()" OnClick="btnSave_Click" /> 

    function myFunction() {

             if (confirm("Are you sure you want to Continue ?")) 
             {
                 return true;
             }
             else
             {
                 return false;
             }
      }

OR from code behind try this:-

Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "myFunction();", true);

OR

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "<script type='text/javascript'>myFunction();</script>", false);