js模态窗口 刷新父页面(求救大侠)

y112102 2011-12-15 04:34:31
代码:
父页面:
<script type="text/javascript">
//弹出模态窗口
function showPopWindow(url, width, height) {
width = parseInt(width) + 30;
height = parseInt(height) + 30;
return window.showModalDialog(url + "&Datetime=" + GetTime(), document, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:0;status:0;scroll:auto;center:1;");
}


function GetTime() {
var theDate = new Date();
var str = theDate.getFullYear() + "-" + (theDate.getMonth() + 1) + "-" + theDate.getDate() + "-" + theDate.getHours() + "-" + theDate.getMinutes() + "-" + theDate.getSeconds();
return str;

}
</script>

html:
<asp:LinkButton ID="btnAdd" runat="server" Text="新增" OnClick="btnAdd_Click" />
<div style="display:none">
<asp:Button ID="btnRefresh" runat="server" Text="刷新父页面" OnClick="btnRefresh_Click" /></div>

后台代码:
protected void btnAdd_Click(object sender, EventArgs e)
{
string script = string.Format("<script>showPopWindow('Default.aspx?ButtonId={0}&op={1}',400,300);</script>", btnRefresh.ClientID, "add");
AllString(this, script);
}
protected void btnRefresh_Click(object sender, EventArgs e)
{
Response.Write("我是子界面刷新父页面");
}
/// <summary>
/// 执行客户端脚本
/// </summary>
/// <param name="P">调用的页面</param>
/// <param name="allCommand">要执行的脚本</param>
public static void AllString(Page P, string allCommand)
{
P.ClientScript.RegisterStartupScript(P.GetType(), "KEY", allCommand);
}

----子页面:
html:
<asp:Button ID="btnSave" runat="server" Text="保存" OnClick="btnSave_Click"
ValidationGroup="v" />
<input type="button" class="button" value="关 闭" onclick="javascript:window.parent.close();" />
<asp:HiddenField ID="hidType" runat="server" />
</asp:Content>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hidType.Value = Request.QueryString["op"];
Response.Write(hidType.Value);
}
}

protected void btnSave_Click(object sender, EventArgs e)
{
StringBuilder sbScript = new StringBuilder();
if (!string.IsNullOrEmpty(Request.QueryString["ButtonId"]))
{
sbScript.AppendFormat("window.dialogArguments.all[\"{0}\"].click();", Request.QueryString["ButtonId"]);
}
sbScript.Append("alert('保存成功!');window.close();");
ClientScript.RegisterStartupScript(this.GetType(), "over", sbScript.ToString(), true);
}


这个问题我一直都没解决 哎~我真的不知道怎么办 虽然我能看懂js但是也没有用 心灰意冷。
大侠们 求解。
...全文
556 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
周祥 2011-12-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 licip 的回复:]
子窗口有一个对象:window.opener就是父窗口对象。 你用这个去操作父窗口, 或者把父窗口的window当成参数传递到子窗口来。
[/Quote]

同意该观点 用 window.opener 来刷新父页面 是最简单的方法

window.opener.document.location.href = window.opener.document.location.href;

y112102 2011-12-20
  • 打赏
  • 举报
回复
没人回答我的问题?还是。。
licip 2011-12-15
  • 打赏
  • 举报
回复
子窗口有一个对象:window.opener就是父窗口对象。 你用这个去操作父窗口, 或者把父窗口的window当成参数传递到子窗口来。
y112102 2011-12-15
  • 打赏
  • 举报
回复
子页面
y112102 2011-12-15
  • 打赏
  • 举报
回复
自页面刷新不了父页面 而且还没关闭 又重新弹出了一张页面

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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