父页面生成模态窗口,模态窗口上的按钮会导致父页面触发回发吗?

发布于 2024-08-19 19:51:02 字数 509 浏览 11 评论 0原文

我有一个 asp.net 网络表单。 表单上有一些用户需要填写的字段。 有一个超链接可打开模式窗口(我正在使用 jquery 和 Prettyphoto,但可能会切换到 http://www.ericmmartin.com/projects/simplemodal/ 因为他的文档更好)

模态窗口包含一个 iFrame,用户可以在其中进行选择并保存记录。

此时我需要关闭该窗口并在父页面上触发回发。

目前,我在最后一页上有一个超链接,其中 target = 父页面,href = 父页面 url。 然后我有一个自动点击它的javascript。我知道这是一个廉价的黑客行为。 然后,它将用户发送回父页面,但页面会重新加载,所有原始数据都会丢失。 这就是问题所在。

最好的方法是什么?

谢谢!

I have a asp.net webform.
There's a few fields on the form that the user will fill out.
There is a hyperlink that opens a modal window (I'm using jquery & prettyphoto, but may switch to http://www.ericmmartin.com/projects/simplemodal/ because his documentation is better)

The modal window contains an iFrame where the user makes a selection and saves a record.

At this point I need to close that window and trigger a postback on the parent page.

Currently I have a hyperlink on the last page where the target = parent and href = the parent page url.
Then I have a javascript that autoclicks it. I know it's a cheap hack.
It then sends the user back to the parent page, however the pages is reloaded and all the original data is lost. This is the problem.

What's the best way to do this?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

峩卟喜欢 2024-08-26 19:51:02

如果父窗口和子 iframe 位于同一域中,那么这应该相当简单。

在 iframe 内部,window.parent 引用外部 window 对象,在外部页面中,它引用自身。

https://developer.mozilla.org/en/DOM/window.parent

所以在iframe中,你可以这样编写代码:

// Check to make sure we're an iframe
if (window.parent !== window) {
  // Run an arbitrary function in the parent window
  var daddy = window.parent;
  daddy.doStuffThatSubmitsAFormInTheParentPage();
}
// Make sure you have that function defined in the parent page.

下面是jsbin中的访问示例。您需要一个控制台才能看到爱情。

http://jsbin.com/ucisi/5

相关代码(如果你想要漂亮的话)

http://jsbin.com/ucisi/5/edit

http://jsbin.com/ucisi/4/edit

If the parent window and the child iframe are on the same domain, then this should be fairly simple.

Inside of the iframe, window.parent refers to the outer window object, and in the outer page, it refers to itself.

https://developer.mozilla.org/en/DOM/window.parent

So in the iframe, you can write code along the lines of:

// Check to make sure we're an iframe
if (window.parent !== window) {
  // Run an arbitrary function in the parent window
  var daddy = window.parent;
  daddy.doStuffThatSubmitsAFormInTheParentPage();
}
// Make sure you have that function defined in the parent page.

Here is an example of the access in jsbin. You'll need a console to see the love.

http://jsbin.com/ucisi/5

The related code if you want it pretty

http://jsbin.com/ucisi/5/edit

http://jsbin.com/ucisi/4/edit

め七分饶幸 2024-08-26 19:51:02

通过亚历克斯的解决方案,我能够解决这个问题。

在父页面上,我有:

<script language="JavaScript">
<!--
    function clickPostBackButton() {
        document.getElementById("<%=PostBackButton.ClientID%>").click();
    }
-->
</script>

<asp:Button CssClass="hide" CausesValidation="false" runat="server" Text="Postback" ID="PostBackButton" />

然后在模式窗口中加载的 iFrame 上。我有一个带有按钮的表格。该按钮将用户带到另一个页面。在此页面上,我有以下代码:

<script language="javascript" type="text/javascript">
    // Check to make sure we're an iframe
if (window.parent !== window) {
  // Run an arbitrary function in the parent window
  var daddy = window.parent;
  daddy.clickPostBackButton();
}
// Make sure you have that function defined in the parent page.

</script>

此时,模式窗口关闭,父页面触发回发。
值得注意的是,我的按钮有 CausesValidation="false",如果没有这个,我的页面就会出现验证问题。感谢您的提示亚历克斯·塞克斯顿

With Alex's solution I was able to solve this.

On the parent page, I have:

<script language="JavaScript">
<!--
    function clickPostBackButton() {
        document.getElementById("<%=PostBackButton.ClientID%>").click();
    }
-->
</script>

<asp:Button CssClass="hide" CausesValidation="false" runat="server" Text="Postback" ID="PostBackButton" />

Then on the iFrame that loads in a modal window. I have a form with button. The button takes the user to another page. On this page I have this code:

<script language="javascript" type="text/javascript">
    // Check to make sure we're an iframe
if (window.parent !== window) {
  // Run an arbitrary function in the parent window
  var daddy = window.parent;
  daddy.clickPostBackButton();
}
// Make sure you have that function defined in the parent page.

</script>

At this point the modal widow is closed and the parent page get a postback triggered.
It's important to note that my button has CausesValidation="false", without this my page had validation issues. Thanks for your tip Alex Sexton

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文