Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

close window with out message box

I have an visual studio web aspx application with a close window command button, named finish on my aspx application web page.  I have code below that closes the page when clicked, but, I stoll receive the warning message.   How can I get the aspx page to simply close "with out the message box requiring a yes or no" to close.

Here is my existing code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
           FinishButton1.Attributes.Add("onclick", "window.opener = top; window.close();")
    End Sub

    Protected Sub FinishButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FinishButton1.Click
                Response.Write("<script language='javascript'> { self.opener = top; self.close() }</script>")

    End Sub
0
cesemj
Asked:
cesemj
  • 8
  • 6
  • 2
2 Solutions
 
surajgupthaCommented:
try javascript:self.close();
0
 
surajgupthaCommented:
I meant ur self.close works for me. It closes the IE window without any warning.
0
 
cesemjAuthor Commented:
I am using IE 7.  Do you think I am missing something like a setting in the browser.
0
Industry Leaders: 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!

 
surajgupthaCommented:
Can you try removing ur page load window.close code?? Just leave the Finish button's Self.close code there
0
 
cesemjAuthor Commented:
I removed the Page_load section and still receive the same message just using:

Protected Sub FinishButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FinishButton1.Click
                Response.Write("<script language='javascript'> { self.opener = top; self.close() }</script>")

    End Sub
0
 
surajgupthaCommented:
ok.. when the warning comes up, say NO and view source to see what is present in the HTML page.
0
 
cesemjAuthor Commented:
First Line: <script language='javascript'> { window.close();}</script>

<input type="submit" name="ctl00$Main$FinishButton" value="Close Button" id="ctl00_Main_FinishButton" /><br />
    <br />
0
 
surajgupthaCommented:
Thats why !!! Notice that the first line has Window.Close in it. are u sure u commented any line that adds a window.close into the page? It should be a self.close for it to close without warnings !
0
 
cesemjAuthor Commented:
I receive the same message when I use self.close

Fist Line after saying no:

<script language='javascript'> { self.close();}</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><link href="../App_Themes/White/Default.css" type="text/css" rel="stylesheet" /><link href="../App_Themes/White/Frame.css" type="text/css" rel="stylesheet" /><title>
      Untitled Page


<input type="submit" name="ctl00$Main$FinishButton" value="Close Button" id="ctl00_Main_FinishButton" /><br />
    <br />
    <a id="ctl00_Main_FinishButton1" href="javascript:__doPostBack('ctl00$Main$FinishButton1','')">Close LinkButton</a><br />
    <br />
    <br />

______________________________________________________________
Protected Sub FinishButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FinishButton.Click
        Response.Write("<script language='javascript'> { self.close();}</script>")

    End Sub
0
 
cesemjAuthor Commented:
This is what I have in the page attached to the button:

Partial Class MemberPages_close_test
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '----FinishButton.Attributes.Add("onclick", "window.close(); return false")
        'FinishButton1.Attributes.Add("onclick", "self.close();")
        '---FinishButton1.Attributes.Add("onclick", "window.opener = null; window.close();")
        'FinishButton1.Attributes.Add("onclick="window.opener=null; window.close(); return false")
    End Sub

    Protected Sub FinishButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FinishButton.Click
        Response.Write("<script language='javascript'> { self.close();}</script>")

    End Sub
End Class
0
 
cesemjAuthor Commented:
It mightr be a problem with the way I open the window, I am looking into that right now and will try to use the window open.

This is what I am currently using:

I open the new window from an hyperlink (version 2.0.0.0 .net) using the NavigateUrl property set to the page and the Target property set to _blank.

Thank you in advance,
0
 
surajgupthaCommented:
Let me know if it works... But i still aint sure why ur self.close doesnt work !!!
0
 
cesemjAuthor Commented:
The command button with the window.open code attached works when I use the command directly on a form, but when I use it from within a InsertItemTemplate it does not work.
0
 
RejojohnyCommented:
windows opened using window.open (javascript) will not give a warning when you try to close it again using javascript .. all other windows will give the warning .. which is your case too, because you are opening the page from a hyperlink using "_blank"

you can change that code to call a javascript function which will use window.open to open the new window ..

Rejo
0
 
RejojohnyCommented:
>>within a InsertItemTemplate it does not work
can you please post the code?

Rejo
0
 
cesemjAuthor Commented:
Hello and thank you,

I created a aspx page and on the page under the Data Tooolbox section, I added a form view control to display records from a db. Moreover, I noticed the that the command button I added to the page named finished and using the following code the closes without a warning when opened from another page, but when I right click on the FormView and select EditTemplate InsertItemTemplate it does not work.  To correct the problem I used the following code :

<asp:LinkButton ID="btnTest" runat="server" Font-Bold="True" OnClientClick="window.open('Test.aspx')">Test</asp:LinkButton> within the OnClientClick of a LinkButton.  


Test Page
------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
           FinishButton1.Attributes.Add("onclick", "window.opener = top; window.close();")
    End Sub

    Protected Sub FinishButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FinishButton1.Click
                Response.Write("<script language='javascript'> { self.opener = top; self.close() }</script>")

    End Sub
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 8
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now