Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Modal Window Close

Posted on 2006-07-04
Medium Priority
Last Modified: 2006-11-18
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.

Question by:radhakrishan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 52

Expert Comment

by:Carl Tawn
ID: 17036175
How are you opening the window ? Where is you code to close the window ?

Author Comment

ID: 17036204
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>";
LVL 52

Accepted Solution

Carl Tawn earned 750 total points
ID: 17036220
You might be better trying to add the code as a client-side click event on the button:

    <asp:Button runat="server" ID="Button1" onclick="javascript:window.close();" />
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 17036304
Hi Carl,

Doing that, gives me a compiler error:

CS1026 ) Expected....
LVL 52

Expert Comment

by:Carl Tawn
ID: 17036320
Can you post the definition of your Button as you have it now ? And also the line that is causing the compile error ?

Author Comment

ID: 17036341
<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.

Author Comment

ID: 17036364
I think I got the solution:

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

This works fine for me.


Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question