如何实现点及按钮关闭模式窗体并刷新父页面

dotnetfly 2010-01-28 01:57:16
我在cs中的代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close()</script>");
}
怎么不能实现啊?
...全文
542 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgh648019074 2011-03-30
  • 打赏
  • 举报
回复
学习执行修改后关闭弹出页面并刷新父页面,有用!
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
多谢大家的帮助,问题已解决
jenny0810 2010-01-28
  • 打赏
  • 举报
回复
学习
CalvinDo 2010-01-28
  • 打赏
  • 举报
回复
弹出页面

function OpenEditWin(strID)
{
var url;
url = "DocumentAdd.aspx?Doc_ID=" +strID+"&action=update";
window.showModalDialog(url,window,'dialogwidth:800px;dialogheight=300px;status=no;help=no;resizable=no;scroll=no;center=yes;location=no');
}

执行修改后关闭弹出页面并刷新父页面

if (result > 0)
{
string url = GetUrl();
Response.Write("<script language=javascript>alert('修改成功!');window.dialogArguments.location.assign('" + url + "');</script>");
Response.Write("<script>window.close();</script>");
Response.Write("<script> window.dialogArguments.location.reload();</script>");
Response.End();

}

弹出窗需要在<head></head>标签中加入<base target="_self" />

测试通过~
zjw19871024a 2010-01-28
  • 打赏
  • 举报
回复
ScriptManager.RegisterStartupScript(this.Page, GetType(), "infor", "alert('添加成功!');window.opener.LinkButton.click();window.close();", true);
这句话加在你子窗体的最后
如果你的子窗体是新增一个东西,那么在你插入语句的后面加上这句话就行了
bool insert=sqlhelp.Update();
if(insert)
ScriptManager.RegisterStartupScript(this.Page, GetType(), "infor", "alert('添加成功!');window.opener.LinkButton.click();window.close();", true);

yan267 2010-01-28
  • 打赏
  • 举报
回复
在父页面提交一个LinkButton按钮,让其隐藏,关闭子页面的时候让LinkButton onclick事件重新刷新页面。

首先在父页面添加一个LinkButton让其text为空,那么就可以隐藏LinkButton,然后注册这个按钮的js,LinkButton.Attributes.Add("onfocus", "javascript:__doPostBack('btnFresh','');");

添加一段JS代码

var sReturn=window.showModalDialog("" + id,'','dialogWidth:420px;dialogHeight:570px,center=yes,status=no,resizable=no,scroll=no,dialogHide=on');;
if (typeof(sReturn) != "undefined")
{
if (sReturn=="1")
{

document.all["btnFresh"].focus();

}
}



然后在子页面提价一下JS代码

function reload()
{
window.parent.returnValue='1';window.close();
}

因为是showModalDialog 所以记住加入 <base target="_self"/>


其实用弹出窗口比较好控制。你自己试试了。
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
我知道是哪里的问题了,我打开的是模式窗体
function OpenChild()
{
window.showModalDialog("AddFolders.aspx","新增文件夹","dialogWidth:450px;dialogHeight:150px;center:yes;help:no;resizable:no;status:no")
}

如果是模式窗体该怎么办
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
我知道是哪里的问题了,我打开的是模式窗体
function OpenChild()
{
window.showModalDialog("AddFolders.aspx","新增文件夹","dialogWidth:450px;dialogHeight:150px;center:yes;help:no;resizable:no;status:no")
}

如果是模式窗体该怎么办
yan267 2010-01-28
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 dotnetfly 的回复:]
用 yan267

protected void Button1_Click(object sender, EventArgs e)
{
        Response.Write(" <script language='javascript'>window.opener.location.href='father.aspx';window.close(); </script>");
}

点击按钮没反应啊

[/Quote]

child的页面是否关闭,father的页面是否重新加载?
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
用 yan267

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>window.opener.location.href='father.aspx';window.close();</script>");
}

点击按钮没反应啊
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
多谢大家,接近了,有点小问题
fpeih 2010-01-28
  • 打赏
  • 举报
回复
Response.Write("<script>window.close();window.opener.location.href=window.opener.location.href</script>");
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
在什么地方用,能不能说清楚点
ScriptManager.RegisterStartupScript(this.Page, GetType(), "infor", "alert('添加成功!');window.opener.LinkButton.click();window.close();", true);
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
我试试看
yan267 2010-01-28
  • 打赏
  • 举报
回复

father.aspx

<script language='javascript'>

function OpenChild()
{
window.open('Child.aspx','anyname','width=530,height=310,status=no,toolbar=no, menubar=no,location=no');
}
</script>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="OpenChild" onclick="OpenChild()" />
</div>
</form>
</body>

Child.aspx

<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Close" OnClick="Button1_Click" />
</div>
</form>
</body>

Child.aspx.cs

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>window.opener.location.href='father.aspx';window.close();</script>");


}


你自己测试看看啊
kele1006 2010-01-28
  • 打赏
  • 举报
回复
关闭模态窗体的时候有一个回传的,可以通过父窗体获取回传进行窗体刷新
zjw19871024a 2010-01-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dotnetfly 的回复:]

[/Quote]

在主页面加一个LinkButton,在LinkButton的单击事件里面重新绑定要绑定的东西
然后在子页面里面关闭时用这句代码
ScriptManager.RegisterStartupScript(this.Page, GetType(), "infor", "alert('添加成功!');window.opener.LinkButton.click();window.close();", true);
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
有没有人啊
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
我再顶
dotnetfly 2010-01-28
  • 打赏
  • 举报
回复
好像不行啊,然后怎么刷新父页面
加载更多回复(5)

62,263

社区成员

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

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

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

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