ASP.NET Ajax: close window after Ajax call?

你说的曾经没有我的故事 提交于 2019-12-11 06:58:35

问题


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)?

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.

Thanks for any advice.


回答1:


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



来源:https://stackoverflow.com/questions/250450/asp-net-ajax-close-window-after-ajax-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!