Help: Problem closing window

G

Guest

Hi,

I have a form with Submit and cancel button. When Cancel button is clicked I
want to close the browser window. Here is my sample form. To make things
simple I have removed the submit button. When I click on the cancel button,
the window doesn’t close. Can someone tell me what mistake I am making here?
Thanks for your help,

Joe

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">

Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Write("<script>self.close();<\/script>")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" Runat="server" Text="Button"
OnClick="Button1_Click" />

</div>
</form>
</body>
</html>
 
S

Steve C. Orr [MVP, MCSD]

You had a typo in your Response.Write line.
It should be this:
Response.Write("<script>self.close();</script>")
 
G

Guest

Hi Steve,

If I use what you suggested -
Response.Write("<script>self.close();</script>") then I get an Compilation
error saying: String constants must end with a double quote.
with line highlighted
Response.Write("<script>self.close();</script>")

This error goes away when I use
Response.Write("<script>self.close();<\/script>")

Notice the escape sequence "\". Not I don't get the error but the window
doesn't close.

Joe
 
S

Steve C. Orr [MVP, MCSD]

Have you tried window.close?




Joe said:
Hi Steve,

If I use what you suggested -
Response.Write("<script>self.close();</script>") then I get an Compilation
error saying: String constants must end with a double quote.
with line highlighted
Response.Write("<script>self.close();</script>")

This error goes away when I use
Response.Write("<script>self.close();<\/script>")

Notice the escape sequence "\". Not I don't get the error but the window
doesn't close.

Joe
 
G

Guest

I'm not sure whats up but I use the same technique written a little diff. and
it always works.


Response.write "<script language=javascript>window.close()</script>"

Never had any trouble. I don't use the parenths on the write function. mabye
try that.

Good luck.
 
G

Guest

falcon, I don't know how you are able to do witout paranthese because asp.net
should give you error.

Anyway when I tried this,

Response.Write("<script language=javascript>window.close()<" & "/script>")

I didn't get any errors and the window was closed too. WoW.

Thanks everybody for your time and help.

Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top