0

i am opening a pop up from code behind(which i am using as waiting image while processing) after that i am doing some activity in background ,when the activity is done i am closing that pop up . the problem is after the activity is over the pop is not getting closed. what i am doing wrong, here is my code snippet:-

    System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<script language='javascript'>");
            sb.Append("var win=");
            sb.Append("window.open('WaitingImage.aspx', 'Wait',");
            sb.Append("'width=800, height=600, menubar=no, resizable=no');window.focus();<");
            sb.Append("/script>");

            Type t = this.GetType();
            if (!ClientScript.IsClientScriptBlockRegistered(t, "PopupScript"))
            {
            ClientScript.RegisterClientScriptBlock(t,"PopupScript", sb.ToString());
            }
        //pop up opened.. now do the processing :-
             uploadFiles();
        //now close the pop up after work is done:-

        System.Text.StringBuilder sbs = new System.Text.StringBuilder();
        sbs.Append("<script language='javascript'>");
        sbs.Append("window.close()");
        sbs.Append("/script>");
        Type tr = this.GetType();
        ClientScript.RegisterClientScriptBlock(tr, "PopupScript", sbs.ToString());
Pranav
  • 8,563
  • 4
  • 26
  • 42

1 Answers1

2

You assign the popup to the win variable, but when you closee you call window.close...

Try to change

 sbs.Append("window.close()");

to

 sbs.Append("win.close()");
2GDev
  • 2,478
  • 1
  • 20
  • 32
  • @2gDev--when u closed the script tag ,the scope of that variable is no more.....then how it will work??? – Pranav Jul 01 '11 at 09:37
  • 1
    puts win in global scope. Also I would do `if (win && !win.closed) win.close();` – mplungjan Jul 01 '11 at 09:40
  • take a look at this line : sbs.Append("/script>"); where is the closing script tag?? I've tested on my local machine and it worked! – 2GDev Jul 01 '11 at 09:40
  • @Pranav : it's not true... where do you read this behavior? When you declare a variable inside a function that variable is inaccessible outside the function, but in this case win is like a global variable. – 2GDev Jul 01 '11 at 09:46
  • it was due to Key used to register your Client Script . – Pranav Jul 01 '11 at 12:22