Closing a window from code behind

J

Jeremy

Looks like this is either too obvious for anyone to address, or it just
isn't done by anyone. There was a question in early sep this year that no
one replied to, and I don't find any other references. So here goes again:

I want to close my popup from an asp codebehind event handler. The
following does not work (this is an event handler for the Login control)

protected void OnLoggedIn(object sender, EventArgs e)
{
Response.Write ("<script language =
javascript>close();</script>");
}

Instead of closing the window and returning to the calling window, the
calling page is opened (again) in the same window.

Jeremy
 
N

Nick Chan

try putting Response.End after it

did u try debug break in onloggedin? does it go there?
 
J

Jeremy

Nick, bless you! Response.end() is the answer.

Mark Rae, in a different thread is saying that this technique of pumping
script into html is a bad thing. Unfortunately, I don't know any other way
to get the window closed from codebehind. Is there some other technique? He
suggests registering a client script, but that begs the question; how to
call the script from codebehind?

Jeremy
 
J

Jon Gonzales

This is the only way, always remember that manipulating windows occur in the
client side, hence the client side script is use to meet this requirements.
 
N

Nick Chan

it is very odd that in your case response.write without response.end
wont work
maybe it has something to do with login control


if response.write without response.end wont work, i doubt registering
client script will

anyway, to register client script :

Page.ClientScript.RegisterStartupScript(Page.GetType,
"scriptName_FreeText", "<script type=""text/javascript"">close()</
script>")

(or RegisterClientScript, i think!)
 

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,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top