[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

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
0
radhakrishan
Asked:
radhakrishan
  • 4
  • 3
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
How are you opening the window ? Where is you code to close the window ?
0
 
radhakrishanAuthor Commented:
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);
            }
0
 
Carl TawnSystems and Integration DeveloperCommented:
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();" />
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
radhakrishanAuthor Commented:
Hi Carl,


Doing that, gives me a compiler error:

CS1026 ) Expected....
0
 
Carl TawnSystems and Integration DeveloperCommented:
Can you post the definition of your Button as you have it now ? And also the line that is causing the compile error ?
0
 
radhakrishanAuthor Commented:
<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.
0
 
radhakrishanAuthor Commented:
I think I got the solution:

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

This works fine for me.

Cheers
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now