父页面生成模态窗口,模态窗口上的按钮会导致父页面触发回发吗?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果父窗口和子 iframe 位于同一域中,那么这应该相当简单。
在 iframe 内部,
window.parent
引用外部window
对象,在外部页面中,它引用自身。https://developer.mozilla.org/en/DOM/window.parent
所以在iframe中,你可以这样编写代码:
下面是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 outerwindow
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:
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
通过亚历克斯的解决方案,我能够解决这个问题。
在父页面上,我有:
然后在模式窗口中加载的 iFrame 上。我有一个带有按钮的表格。该按钮将用户带到另一个页面。在此页面上,我有以下代码:
此时,模式窗口关闭,父页面触发回发。
值得注意的是,我的按钮有 CausesValidation="false",如果没有这个,我的页面就会出现验证问题。感谢您的提示亚历克斯·塞克斯顿
With Alex's solution I was able to solve this.
On the parent page, I have:
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:
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