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.A dd("onclic k", "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
Here is my existing code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
FinishButton1.Attributes.A
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
try javascript:self.close();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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.
ASKER
First Line: <script language='javascript'> { window.close();}</script>
<input type="submit" name="ctl00$Main$FinishBut ton" value="Close Button" id="ctl00_Main_FinishButto n" /><br />
<br />
<input type="submit" name="ctl00$Main$FinishBut
<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 !
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.cs s" 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$FinishBut ton" value="Close Button" id="ctl00_Main_FinishButto n" /><br />
<br />
<a id="ctl00_Main_FinishButto n1" href="javascript:__doPostB ack('ctl00 $Main$Fini shButton1' ,'')">Clos e 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
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/
Untitled Page
<input type="submit" name="ctl00$Main$FinishBut
<br />
<a id="ctl00_Main_FinishButto
<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
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.Attribut es.Add("on click", "window.close(); return false")
'FinishButton1.Attributes. Add("oncli ck", "self.close();")
'---FinishButton1.Attribut es.Add("on click", "window.opener = null; window.close();")
'FinishButton1.Attributes. Add("oncli ck="window .opener=nu ll; 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
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.Attribut
'FinishButton1.Attributes.
'---FinishButton1.Attribut
'FinishButton1.Attributes.
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
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,
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 !!!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>within a InsertItemTemplate it does not work
can you please post the code?
Rejo
can you please post the code?
Rejo
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.asp x')">Test< /asp:LinkB utton> 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.A dd("onclic k", "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
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 Page
------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
FinishButton1.Attributes.A
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