在 JQuery UI 对话框中加载 aspx 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4629899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Loading aspx page in JQuery UI dialog
提问by Rahul
I have a aspx page where I have a linkbutton and upon clicking that link button I am calling another aspx page passing a parameter in a pops up window, like below:
我有一个 aspx 页面,其中有一个链接按钮,单击该链接按钮后,我正在调用另一个 aspx 页面,在弹出窗口中传递一个参数,如下所示:
<asp:linkbutton id='lbtn1' onClick=<%#"window.open('/testsite/mypage.aspx?param=abcd');return false"%>
Till now it was working fine but now I have to include my page to another site where they have used JQuery for popup dialog and asked me to load my page using the same.
直到现在它工作正常,但现在我必须将我的页面包含到另一个站点,在那里他们使用 JQuery 进行弹出对话框并要求我使用相同的方式加载我的页面。
I am really new to JQuery and have no idea about. I tried searching through this forum and google but no luck.
我对 JQuery 真的很陌生,不知道。我尝试通过这个论坛和谷歌搜索,但没有运气。
Can someone please help me and show me how can I achieve this (please don't mind but a code example would be really appreciated).
有人可以帮助我并告诉我如何实现这一点(请不要介意,但非常感谢代码示例)。
A lot thanks.
非常感谢。
回答by Ahmed Nuaman
Do you mean loading a page through an iframe into a modal/lightbox style? Try using a lightbox pluginor reading up on the jQuery UI dialog.
您的意思是通过 iframe 将页面加载到模态/灯箱样式中吗?尝试使用灯箱插件或阅读jQuery UI 对话框。
If you do decide to use the jQuery UI dialog, you can do something like this:
如果您决定使用 jQuery UI 对话框,您可以执行以下操作:
<div id="dialog">
<iframe src="page.html"></iframe>
</div>
...
$( "#dialog" ).dialog();
回答by Jamie Treworgy
There is another way, though for the purposes of a modal popup an iframe seems a perfectly legitimate solution. But you could load all the html of the target page with an ajax query, and populate the modal dialog with it. Using jQuery:
还有另一种方式,尽管出于模态弹出的目的,iframe 似乎是一个完全合法的解决方案。但是您可以使用 ajax 查询加载目标页面的所有 html,并用它填充模态对话框。使用jQuery:
<script type="text/javascript">
function showPanel(panelID)
{
$panel = $('#'+panelID);
$.ajax({
url: "/testsite/mypage.aspx",
type: "GET",
dataType: "html",
async: false,
data: { "param": "abcd"
},
success: function (obj) {
// obj will contain the complete contents of the page requested
// use jquery to extract just the html inside the body tag
$content=$(obj).find('body').html();
// then update the dialog contents with this and show it
$panel.html($content);
$panel.dialog();
}
});
}
</script>
<div id="dialog">
</div>
Then call this from your click event with the id of the panel.
然后使用面板的 id 从您的点击事件中调用它。
<asp:LinkButton id="lbtn1" onClick="showPanel('dialog');return false;" />
Note: while this will probably work, if your intent to simply have a link do something on the client, a LinkButton
doesn't really make sense, since it is by definition a postback control. So, if you want it to be rendered as a hyperlink for styling reasons, use a HyperLink
control or just an HTML link. If not, just put a "div" or "span" around the link text or content and use jQuery to add a click event to it. There are lots of discussions on this sort of thing on SO.
注意:虽然这可能会奏效,但如果您只想让链接在客户端上做某事,aLinkButton
并没有真正意义,因为它根据定义是回发控件。因此,如果出于样式原因希望将其呈现为超链接,请使用HyperLink
控件或仅使用 HTML 链接。如果没有,只需在链接文本或内容周围放置一个“div”或“span”,然后使用 jQuery 为其添加点击事件。在 SO 上有很多关于这类事情的讨论。
回答by Adrian
The only way I can think to serve a dynamic aspx page where the page is built (partially or fully) serverside is to add an iframe to the popup and set it's target to the url you wish to load.
我能想到的提供动态 aspx 页面的唯一方法是在服务器端构建页面(部分或全部)是将 iframe 添加到弹出窗口并将其目标设置为您希望加载的 url。
Hate iframes but I think this might be the only way.
讨厌 iframe,但我认为这可能是唯一的方法。