Response.End 之后关闭窗口

发布于 2024-10-02 18:43:54 字数 445 浏览 3 评论 0原文

例如,我有一个带有 ListView 且处于编辑模式的表单。
发生了一些事情,导致列表视图正在使用的表不再可用。
我只想在用户点击“保存”时能够关闭窗口。

在Page_Load中,我检查表是否可用,如果不可用,我调用RegisterClientScriptBlock(type,name,"window.close()")。但是,处理仍然发生,然后转到 ListView1_ItemUpdating 事件

Page_Load 中,如果表不存在,我可以调用 Response.End 来停止处理,但是,由于脚本从未注册,窗口仍然保持打开状态。

有什么方法可以停止处理并关闭窗口,而不必在我的所有方法中放置自定义 IsTableValid() 检查吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

习ぎ惯性依靠 2024-10-09 18:43:54

Oded 提供的答案在 Page_Load 中不起作用,我不知道为什么。 eych 提供的答案有效。然而,如果您不想保留额外的 html 文件并进行重定向,您可以使用类似以下内容的内容:

Response.Clear();
Response.Write("<script>window.close();</script>");
Response.Flush();
Response.End();

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();
百合的盛世恋 2024-10-09 18:43:54

刷新响应在结束之前将所有数据发送到浏览器:

RegisterClientScriptBlock(type,name,"window.close()")
Response.Flush()
Response.End()

您可能需要 在注册脚本之前清除响应,以确保响应缓冲区中没有其他内容。

如果您只想清除其中一个而不清除另一个,还有 ClearHeadersClearContent 方法。

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.

好多鱼好多余 2024-10-09 18:43:54

一种解决方案,kludgey,但可以在其他地方使用:

Response.Redirect("close.html")

其中 close.html 只是

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

one solution, kludgey, but can be used elsewhere:

Response.Redirect("close.html")

where close.html just has

  <script>
  window.close();
  </script>
郁金香雨 2024-10-09 18:43:54

试试这个:

HttpContext.Current.ApplicationInstance.CompleteRequest();

微软自己该响应.End 只是为了向后兼容:

此方法仅提供给
与 ASP 的兼容性——即
与基于 COM 的兼容性
网络编程技术
早于 ASP.NET

不确定它是否能解决您的问题,但至少 Microsoft 不会有借口..:)

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.. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文