Closing browser window from server side in asp.net

G

Guest

Hi

I hope some one has an answer to this.

I have a button in an aspx page . On server click of this button, i perform
some operation. Once the operation is performed i want to close this window
automatically.

Pls help
Sileesh
 
G

Guest

i don;t think you can literally close a browser from a server side script.
what you can do instead is to pass a client side script after you've done
your process on the server side..

sample..
private sub Button1_Click()

--do your server side processing here.

--after you're done load the close window script
Dim strscript As String = "<script
language=javascript>window.top.close();</script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strscript)
End If

end sub

hope this helps..
 
G

Guest

HI Allan

Thx. It works great.

Allan said:
i don;t think you can literally close a browser from a server side script.
what you can do instead is to pass a client side script after you've done
your process on the server side..

sample..
private sub Button1_Click()

--do your server side processing here.

--after you're done load the close window script
Dim strscript As String = "<script
language=javascript>window.top.close();</script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strscript)
End If

end sub

hope this helps..
 
Joined
Sep 21, 2008
Messages
1
Reaction score
0
Since this came up first in google, I thought I'd post a quick update:

the 'newer' proper code is:

Dim strscript As String = "<script language=javascript>window.top.close();</script>"
If (Not ClientScript.IsStartupScriptRegistered("clientScript")) Then
ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", strscript)
End If

works great in .net 3.5

Cheers.
 

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