Response.End 之后关闭窗口
例如,我有一个带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Oded 提供的答案在 Page_Load 中不起作用,我不知道为什么。 eych 提供的答案有效。然而,如果您不想保留额外的 html 文件并进行重定向,您可以使用类似以下内容的内容:
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:
刷新
响应在结束之前将所有数据发送到浏览器:您可能需要
在注册脚本之前清除
响应,以确保响应缓冲区中没有其他内容。如果您只想清除其中一个而不清除另一个,还有
ClearHeaders
和ClearContent
方法。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.一种解决方案,kludgey,但可以在其他地方使用:
Response.Redirect("close.html")
其中
close.html
只是one solution, kludgey, but can be used elsewhere:
Response.Redirect("close.html")
where
close.html
just has试试这个:
微软自己说该响应.End 只是为了向后兼容:
不确定它是否能解决您的问题,但至少 Microsoft 不会有借口..:)
Try 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.. :)