Link to home
Start Free TrialLog in
Avatar of cesemj
cesemj

asked on

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
Avatar of surajguptha
surajguptha
Flag of United States of America image

try javascript:self.close();
ASKER CERTIFIED SOLUTION
Avatar of surajguptha
surajguptha
Flag of United States of America 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
Avatar of cesemj
cesemj

ASKER

I am using IE 7.  Do you think I am missing something like a setting in the browser.
Can you try removing ur page load window.close code?? Just leave the Finish button's Self.close code there
Avatar of cesemj

ASKER

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
ok.. when the warning comes up, say NO and view source to see what is present in the HTML page.
Avatar of cesemj

ASKER

First Line: <script language='javascript'> { window.close();}</script>

<input type="submit" name="ctl00$Main$FinishButton" value="Close Button" id="ctl00_Main_FinishButton" /><br />
    <br />
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 !
Avatar of cesemj

ASKER

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
Avatar of cesemj

ASKER

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
Avatar of cesemj

ASKER

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,
Let me know if it works... But i still aint sure why ur self.close doesnt work !!!
Avatar of cesemj

ASKER

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.
SOLUTION
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
>>within a InsertItemTemplate it does not work
can you please post the code?

Rejo
Avatar of cesemj

ASKER

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