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.