【问题标题】:Refresh parent page after Greybox closeGreybox 关闭后刷新父页面
【发布时间】:2010-12-24 07:54:38
【问题描述】:

首先祝大家圣诞快乐:)

我有一个博客,人们可以在那里制作 cmets。我现在决定将“writecmets.aspx”文件放在灰盒弹出窗口中。它可以工作,但我想在写完评论后从代码隐藏(或javascript)关闭窗口。然后我想刷新博客页面(父页面)以显示新评论。

这是打开灰盒(writecmets.aspx)页面的代码:

<a href='WriteComments.aspx?BlogId=<%# DataBinder.Eval(Container, "DataItem.id") %>' rel="gb_page_center[500, 500]">Skriv kommentar</a>

在 writecmets.aspx 文件中,我只有 2 个文本框和 1 个按钮(保存按钮)。 如何让灰盒窗口自行关闭,然后以某种方式刷新 blog.aspx?或者可能只是当前 cmets 的特定更新面板?

编辑 我让它工作了,我不得不把这段代码放在代码隐藏中,在 db-insert 之后:Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.GB_hide();", true); 而对于父页面的刷新,我将第 12 行的 gb_scripts.js 文件从 false 修改为 true:this.reload_on_close=true;

圣诞快乐! :)

再次编辑 实际上,我对其进行了一些修改,因此,我将 gb_scripts.js 文件恢复为默认状态,而我只是在 db-insert 之后的 WriteComments.aspx 代码隐藏文件中的以下代码行:

Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.window.location.reload();parent.parent.GB_hide();", true);

现在,灰盒正在关闭,然后,博客页面正在刷新,就像我想要的那样:)

【问题讨论】:

    标签: javascript asp.net greybox


    【解决方案1】:

    当我正在寻找类似的行为时,这适用于我的情况: http://www.phpfreaks.com/forums/index.php?topic=235378.0

    "请浏览这个文件 (gb_scripts.js) 在第 12 行 改变'this.reload_on_close=false;'到 'this.reload_on_close=true' 和第 67 行 改变'window.location.reload();'到 'window.location.reload(true);' 并做了 « 最后编辑: 2010 年 12 月 20 日,上午 4:38:42 由 shashidharkumar »"

    【讨论】:

      【解决方案2】:

      评论成功保存到数据库后,在页面中呈现以下javascript:

      window.opener.reload();
      window.close();
      

      保存成功后,在您的 WriteComments.aspx.cs 中添加以下代码以在 HTML 中呈现 javascript:

      if (!IsClientScriptBlockRegistered("CloseMe"))
      {
              String cstext1 = "<script type=\"text/javascript\">" +
                  "window.opener.refresh(); window.close();</" + "script>";
              RegisterStartupScript("CloseMe", cstext1 );
      }
      

      【讨论】:

      • 谢谢!但我是 javascript 的新手。在成功的 db-insert 之后,如何从代码隐藏中“运行”它?
      • 用示例更新了之前的帖子。
      • 谢谢!但是现在,当点击保存按钮时,它只是在按钮旁边写下文本“CloseMe”..
      • 我的错,之前交换了参数,请尝试更新。
      • 在 Chrome 控制台中显示:Uncaught TypeError: Cannot call method 'reload' of null (anonymous function)。
      【解决方案3】:
      【解决方案4】:

      我得到了关闭功能!这是我必须使用的代码: Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "parent.parent.GB_hide();", true);现在我只需要以某种方式刷新父页面 :)

      【讨论】:

        【解决方案5】:

        这里有很好的解释ANSWER,步骤简单:http://www.codeofaninja.com/2010/12/how-to-refresh-greybox-parent-page.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-05-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多