e.g. I have a form with a ListView
that is in edit mode.
Something happens so that the table the Listview is using is no longer available.
I just want to be able to close the window if the user hits 'save'.
In Page_Load
, I check if the table is available, if not, I call RegisterClientScriptBlock(type,name,"window.close()").
However, processing still occurs, and it goes to ListView1_ItemUpdating event
.
In Page_Load
, if the table doesn't exist, I can call Response.End to stop processing, however, the window still stays up since the script never registered.
Any way to stop processing and close the window without having to put a custom IsTableValid()
check in all of my methods?
one solution, kludgey, but can be used elsewhere:
Response.Redirect("close.html")
where
close.html
just hasTry this instead:
Microsoft themselves say that Response.End is there only for backward compatibility:
Not sure it will solve your problem but at least Microsoft won't have an excuse.. :)
The answer provided by Oded doesn't work from Page_Load, I don't know why. The answer provided by eych works. Yet, if you don't want to keep an extra html file and make a redirect, you can use something like:
Flush
the response to send all data to the browser before ending it:You may want to
Clear
the response before registering the script, in order to ensure that there is nothing else in the response buffer.There are also
ClearHeaders
andClearContent
methods if you only want to clear one and not the other.