代码:
父页面:
<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但是也没有用 心灰意冷。
大侠们 求解。
父页面:
<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但是也没有用 心灰意冷。
大侠们 求解。
同意该观点 用 window.opener 来刷新父页面 是最简单的方法 window.opener.document.location.href = window.opener.document.location.href;