Closing a window from code behind

  • Thread starter Thread starter Jeremy
  • Start date Start date
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
 
try putting Response.End after it

did u try debug break in onloggedin? does it go there?
 
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
 
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.
 
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!)
 
Back
Top