开发者

closing a window after Response.End

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.


one solution, kludgey, but can be used elsewhere:

Response.Redirect("close.html")

where close.html just has

  <script>
  window.close();
  </script>


Try this instead:

HttpContext.Current.ApplicationInstance.CompleteRequest();

Microsoft themselves say that Response.End is there only for backward compatibility:

This method is provided only for compatibility with ASP—that is, for compatibility with COM-based Web-programming technology that preceded ASP.NET

Not sure it will solve your problem but at least Microsoft won't have an excuse.. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜