如何在弹出窗口关闭时调用父窗口服务器端方法? [英] how to call parent window server side method on popup close?

查看:60
本文介绍了如何在弹出窗口关闭时调用父窗口服务器端方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在通过window.open打开一个页面的弹出窗口(弹出窗口),现在我想当我同时关闭该弹出窗口时,应调用父页面上的方法吗?我正在使用此代码打开弹出窗口

Hi,
I am opening a popup(a popup page) window from a page through window.open now I want that when I close that popup window at the same time a method on parent page should be called? I m using this code to open popup

string newPage = "TestPopUp.aspx";
ScriptManager.RegisterStartupScript(Page, GetType(), "onClick", "window.open(''" + ResolveClientUrl(newPage) + "'', ''UpdateRecord'', ''toolbar=no,location=center,status=no,menubar=no,scrollbars=yes,resizable=no,width=500,height=300,top=200, left=200'');", true);



和这段代码来关闭弹出窗口



and this code to close popup

ScriptManager.RegisterStartupScript(Page, this.GetType(), "onAddNew", "window.close();", true);


现在告诉我在关闭此弹出窗口时可以调用我的服务器端父页面方法BindGridview().
在此先感谢.


Now tell me can I call my server side parent page method BindGridview() at the time of closing this popup.
Thanks in advance.

推荐答案

在"Not PostBack" IF语句中使用此方法.
use this inside "Not PostBack" IF Statement..

if(!IsPostBack)
{
   if(Request.QueryString["fromChild"] != null && Request.QueryString["fromChild"]=="1")
   {
      BindGridView();
   }
} 


尝试一下..

在您的子窗口中,编写一个JavaScript函数以关闭..

try this..

In your child window write one javascript function for close..

function close()
{
     window.opener.location.href = 'http://parentPage.aspx?fromChild=1';
     self.close();
}



在关闭时调用此函数.



call this function on close..

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "onAddNew", "close()", false);




在您的父页面PageLoad中,检查查询字符串..




In your parent page PageLoad check the query string..

if(Request.QueryString["fromChild"]=="1")
{
    BindGridView();
}



希望这会有所帮助..
如果解决了您的问题,请投票



hope this helps..
Vote it if solved your problem


@Karthik Harve
当我单击更新按钮以关闭弹出窗口时,此解决方案不起作用.弹出窗口未关闭,而是在弹出屏幕上显示字符串"close()":(
@Karthik Harve
this solution is not working when I click on update button to close popup. The pop up is not closed rather a string "close()" is appeared on the popup screen :(


这篇关于如何在弹出窗口关闭时调用父窗口服务器端方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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