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?
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:
Response.Clear();
Response.Write("<script>window.close();</script>");
Response.Flush();
Response.End();
Flush the response to send all data to the browser before ending it:
RegisterClientScriptBlock(type,name,"window.close()")
Response.Flush()
Response.End()
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 and ClearContent methods if you only want to clear one and not the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With