积极答复者
弹出窗体关闭刷新父页面问题

问题
-
我使用javascript:window.showModalDialog('../SubBusinessType.aspx','window','dialogWidth:600px;dialogHeight:500px;help:0;scroll:1;status:no;');弹出一个窗体,点击该窗体的关闭按钮如何刷新父窗体
学习,学习,再学习..........- 已移动 Sheng Jiang 蒋晟 2009年10月9日 12:35 客户端脚本问题 (发件人:ASP.NET 与 AJAX)
答案
-
父窗体:Parent.aspx----------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { Response.Write(Guid.NewGuid().ToString()); } </script> <!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 id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <input type="button" value="Show" onclick="ShowWindow('Child.aspx');" /> <script type="text/javascript"> function ShowWindow(url) { var ret = window.showModalDialog(url, 'window', 'dialogWidth:600px;dialogHeight:500px;help:0;scroll:1;status:no;'); if (ret == "OK") { window.location.reload(); } } </script> </form> </body> </html>
子窗体:Child.aspx
----------------------------------------------------------------------<%@ Page Language="C#" AutoEventWireup="true" %> <!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"> <input type="button" value="Close" onclick="window.returnValue='OK';window.close();" /> </form> </body> </html>
知识改变命运,奋斗成就人生!- 已建议为答案 孟宪会Moderator 2009年10月9日 9:17
- 已标记为答案 ysyy 2009年10月11日 7:51
全部回复
-
你好!在关闭关执行 js 的 window.opener.location.reload();
知识改变命运,奋斗成就人生!- 已建议为答案 Raymond TangModerator 2009年10月9日 8:48
- 取消建议作为答案 孟宪会Moderator 2009年10月9日 9:17
-
window.parent.location.reload();也可以 不过这两种方法都没有公共的标准 可能在一些浏览器中会出错
window.location.reload();
最好的办法是在模式窗体关闭前 设置window.returnValue
然后父窗体判断返回的值的类型是否等于undefined 这样可以控制是否刷新
或者直接在window.showModalDialog这行代码下边添加刷新的代码
Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!http://hi.baidu.com/1987raymond -
父窗体:Parent.aspx----------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { Response.Write(Guid.NewGuid().ToString()); } </script> <!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 id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <input type="button" value="Show" onclick="ShowWindow('Child.aspx');" /> <script type="text/javascript"> function ShowWindow(url) { var ret = window.showModalDialog(url, 'window', 'dialogWidth:600px;dialogHeight:500px;help:0;scroll:1;status:no;'); if (ret == "OK") { window.location.reload(); } } </script> </form> </body> </html>
子窗体:Child.aspx
----------------------------------------------------------------------<%@ Page Language="C#" AutoEventWireup="true" %> <!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"> <input type="button" value="Close" onclick="window.returnValue='OK';window.close();" /> </form> </body> </html>
知识改变命运,奋斗成就人生!- 已建议为答案 孟宪会Moderator 2009年10月9日 9:17
- 已标记为答案 ysyy 2009年10月11日 7:51
-
如果在父页面
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="XXX" CommandName="XXX"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代码:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "XXX")
{
int index = ((GridViewRow)((Button)e.CommandSource).NamingContainer).RowIndex;
string productId = GridView1.DataKeys[index].Value.ToString();
System.Web.UI.ScriptManager.RegisterStartupScript(this, Page.GetType(), "ajaxjs", "window.showModalDialog('a.aspx?productid=" + productId +"');", true);
}
}
弹出一个窗体
则关闭这个弹出窗体后如何刷新父页面?????
学习,学习,再学习..........