ASP.NET AJAX:Ajax调用后,关闭窗口? [英] ASP.NET Ajax: close window after Ajax call?

查看:172
本文介绍了ASP.NET AJAX:Ajax调用后,关闭窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET AJAX。我怎么能告诉浏览器服务器调用完成(服务器端code)?

I'm using ASP.NET Ajax. How can I tell the browser to close the current window after the server call finishes (server-side code)?

我能够做到这一点的服务器方法使用ASP.NET AJAX的方法的ScriptManagerRegisterDataItem(一个按钮单击处理程序中):

I managed to do this using the ASP.NET Ajax's ScriptManager method "RegisterDataItem" in the server method (inside a button click handler):

sm.RegisterDataItem(ActionLabel, "action:closewindow")

和一个隐藏的标签和处理它在客户端上是这样的:

and a hidden Label and handling it this way on the client:

function PageLoadingHandler(sender, args)
{
    var dataItems = args.get_dataItems();
    if (dataItems['ActionLabel'] == 'action:closewindow') {
        window.close()
    }
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);

但感觉。必须有一个更优雅的方式来做到这一点。

But it feels dirty. There must be a more elegant way to do this.

感谢您的任何建议。

推荐答案

如果我理解你的权利,登记 window.close()的 ScriptManagers 的RegisterStartupScript 对事件处理方法应该工作。有关使用细节 ScriptManager.RegisterStartupScript 看<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerstartupscript.aspx\"相对=nofollow> MSDN

If I understood you right, registering window.close() with ScriptManagers RegisterStartupScript method on event handler should work. For details on using ScriptManager.RegisterStartupScript see MSDN

这篇关于ASP.NET AJAX:Ajax调用后,关闭窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆