关闭子窗口,局部刷新父窗口的问题

eceg 2008-09-12 04:20:18
Response.Write("<script>");
Response.Write("dialogArguments.location.assign(dialogArguments.location.href);");
Response.Write("window.close();}");
我在子窗口用的是以上方法,但它是全部刷新包括!Ispostback{}里面的也执行了,我现在不想让它执行!Ispostback{}里的有什么办法没?
...全文
368 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
daishengs 2008-09-13
  • 打赏
  • 举报
回复
弹出页关闭时执行父页的JS代码,再让JS执行AJAX操作以达到父页局部刷新,一般原理就是这样
eceg 2008-09-13
  • 打赏
  • 举报
回复
先谢谢个位。等到放假结束了。我到公司试试看,好了回头揭贴
Eray 2008-09-12
  • 打赏
  • 举报
回复
哪有那么复杂.方法很多.给你个最简单的.
1在父页,放一个刷新按钮(不想显示可以隐藏起来),双击它,在事件中刷新GridView
2
为弹出页的关闭按钮事件加属性:OnClientClick="window.opener.form1.Button1.click();window.close();"
弹出页要用window.open,不能用window.showModalDialog
Magic_YJL 2008-09-12
  • 打赏
  • 举报
回复
做个简单的例子,供楼主参考一下。
建两个aspx页面:Default.aspx,Default2.aspx
建一个html页面:HTMLPage.htm

相关代码如下:

Default.aspx前台跟后台

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/C#">

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function showDialog()
{
return window.showModalDialog( "HTMLPage.htm","","dialogWidth:540px;dialogHeight:272px;center:yes;status:no;help:no;scroll:no");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
</form>
</body>


Default.aspx.cs后台:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Button1.Attributes.Add("onclick", "return showDialog()");
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("更新了!");
}
}

</html>



Default2.aspx前台跟后台

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="更新父窗体"></asp:ListItem>
<asp:ListItem Text="不更新父窗体"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>


Default2.aspx.cs后台:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
if(this.DropDownList1.SelectedIndex==0)
Response.Write("<script> window.returnValue = true;window.close();</script>");
else
Response.Write("<script> window.returnValue = false;window.close();</script>");
}
}



HTMLPage.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
</head>
<body>
<iframe src="Default2.aspx" width="100%" height="100%"></iframe>
</body>
</html>




代码都完整的贴出来了,其中的原理自己体会一下.

Coco孙 2008-09-12
  • 打赏
  • 举报
回复
用Ajax可以
或者象父页面传个值,然后做个判断
另外最好清一下缓存
tonyze 2008-09-12
  • 打赏
  • 举报
回复
用Ajax可以
或者象父页面传个值,然后做个判断
另外最好清一下缓存
满衣兄 2008-09-12
  • 打赏
  • 举报
回复

Response.Write(" <script>");
Response.Write("parent.location.href='a.aspx?flag=1';");
//Response.Write("opener.location.href='a.aspx?flag=1';");
Response.Write("window.close();}");


string strFlag = Request.QueryString["flag"];
if(strFlag=="1")
{
...
}
else
{
...
}

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧