子窗口刷新 [英] Child window refresh

查看:97
本文介绍了子窗口刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关闭表示"X"符号的窗口后,如果有任何更改,则仅我要刷新父页面,否则就不刷新.
javascript中有可能吗?
如果是
请建议我可能性.

After closing the window that means ''X'' symbol click if any changes are there then only i want to refresh my parent page else not .
is it possible in javascript ?
if it is
please suggest me the possibility .

推荐答案

var objWindow = window.open('asdf');
objWindow.location.reload();


1.将脚本管理器控件添加到您的子页面(如果尚不存在).
2.现在,您可以在页面中添加两个方法:pageLoad()在页面加载时运行.和pageUnload()在关闭页面时运行.

3.在父文档中,添加一个隐藏的输入控件,例如:

< input type ="hidden" id ="inpRefresh" value ="0"/>

4在子页面"中,还添加一个隐藏的输入控件,如下所示:

< input type ="hidden" id ="inpRefreshParent" value ="0"/>

5.在子窗口页面(aspx)中,添加javascript函数"pageUnload",然后在父文档的隐藏控件中设置一个类似于value的标志,如下所示,
< script type ="test/javascript">

函数pageUnload()
{
parent.document.getElementById(``inpRefresh'').value = document.getElementById(``inpRefreshParent'').value;

}
</script>

现在,在子页面的服务器端方法中,您正在执行一些数据保存操作,请将此隐藏输入的值设置为"1".

例如inpRefreshParent.Value ="1";

6.在父页面中,说一个按钮单击,您正在打开子窗口.
然后,该函数应如下所示:

函数ShowChildPage()
{
window.showModalDialog(ChildPageurl,参数,功能选项);
if(document.getElementById(``inpRefresh'').value ==``1'')
{
document.getElementById(''inpRefresh'').value =``0'';//重置值
返回true; //这将执行按钮的服务器端单击事件,//您可以重新加载数据
}
其他
{
返回false;
}
}

用于打开子页面的按钮的代码将如下所示:

< asp:button runat ="server" id ="btnShow" onclientclick ="javascript:return ShpwChildPage();" onclick ="btnShow_Click" xmlns:asp =#unknown"/>


服务器端的click事件处理程序将如下所示:

受保护的无效btnShow_Click(对象发送者,EventArgs e)
{
//重新加载数据
}


希望对您有帮助:)
1. Add a Script Manager control to your child page (if it is not already there).
2. Now you can add two methods in your page : pageLoad() that runs when the page is loaded. and pageUnload() which runs when the page is closed.

3. In Parent document, Add a hidden input control like :

<input type="hidden" id="inpRefresh" value="0" />

4 In Child Page also add a hidden input control as follows :

<input type="hidden" id="inpRefreshParent" value="0" />

5. In child window page (aspx) , add javascript function "pageUnload" and in that, set a flag like value in parent document''s hidden control as follows ,
<script type="test/javascript">

function pageUnload()
{
parent.document.getElementById(''inpRefresh'').value = document.getElementById(''inpRefreshParent'').value;

}
</script>

Now in the child page''s server side method where you are doing some data saving operation, set value of this hidden input to ''1''.

e.g. inpRefreshParent.Value = "1";

6. In parent page, say on a button click you are opening the child window.
Then that function should be like this :

function ShowChildPage()
{
window.showModalDialog( ChildPageurl, arguments, feature options);
if(document.getElementById(''inpRefresh'').value == ''1'')
{
document.getElementById(''inpRefresh'').value = ''0'';//reset the value
return true; //this will execute server side click event of the button //which you can reload the data
}
else
{
return false;
}
}

The code for the button that will open the child page will be like this:

<asp:button runat="server" id="btnShow" onclientclick="javascript:return ShpwChildPage();" onclick="btnShow_Click" xmlns:asp="#unknown" />


and the server side click event handler will be like this :

protected void btnShow_Click(object sender,EventArgs e)
{
//Reload data
}


Hope this helps you :)


这篇关于子窗口刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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