Link to home
Start Free TrialLog in
Avatar of radhakrishan
radhakrishan

asked on

Modal Window Close

Hi Experts,


could anyone tell me, how to close a modal window on click of a button.

Using window.close does'nt seems to work.


Cheers
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

How are you opening the window ? Where is you code to close the window ?
Avatar of radhakrishan
radhakrishan

ASKER

Hi Carl,

The window is opened from another page and on click of a close button i wrote the following code:
(The click button is on the modal window page)

private void Button1_Click(object sender, System.EventArgs e)
            {
                string s1 = "<script>window.close();</script>";
                  Response.Write(s1);
            }
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Carl,


Doing that, gives me a compiler error:

CS1026 ) Expected....
Can you post the definition of your Button as you have it now ? And also the line that is causing the compile error ?
<asp:Button id="Button1" style="Z-INDEX: 105; LEFT: 224px; POSITION: absolute; TOP: 216px" runat="server"
                        Width="96px" Text="Close" onclick="javascript:window.close();"></asp:Button>


And the highlighted line is the first line:

with same error CS1026 ) Expected.
I think I got the solution:

this.Button1.Attributes.Add("onclick", "window.close(); return false;");

This works fine for me.

Cheers