简体   繁体   English

如何在asp.net c#中将子页面的内容加载到div中

[英]How to load content of child page into div in asp.net c#

I need to load content of child page-1 into div of child page-2.我需要将子页面 1 的内容加载到子页面 2 的 div 中。 I have tried to load the content using jquery, but it loads entire page including master page.我尝试使用 jquery 加载内容,但它加载了整个页面,包括母版页。 I want to load only child page content excluding master page content.我只想加载不包括母版页面内容的子页面内容。 Is there any way to do this?有没有办法做到这一点?

I am betting that you have jQuery available here.我敢打赌,您可以在这里使用 jQuery。

So, to load a page - even one that was setup as a child to a master page?那么,要加载一个页面 - 即使是作为母版页面的子页面设置的页面?

this works quite well:这很有效:

<asp:Button ID="Button1" runat="server" Text="Button"  OnClientClick="getpage();return false"   />

<div id="myotherpage">
</div>

<script>
    function getpage() {
        alert('hello');
        $.get("/WebForm5.aspx", function (data) {
            $("#myotherpage").html(data);
        });
    }
</script>

So, in above, I want to get/grab/load the WebForm5.aspx page right into that div.因此,在上面,我想将 WebForm5.aspx 页面直接获取/抓取/加载到该 div 中。

In this example, EVEN if WebForm5.aspx WAS attached to master, the above seems to work rather nice.在这个例子中,即使 WebForm5.aspx 附加到 master,上面的似乎也很好用。

The other way?另一种方法? Well of course the iFrame idea - that works.嗯,当然 iFrame 的想法 - 行得通。 (but a iFrame would also re-produce the menu bar - the above does not). (但 iFrame 也会重新生成菜单栏 - 上面没有)。

but, above does work quite nice - even the code behind for that page seems to run just fine.但是,上面确实工作得很好 - 甚至该页面背后的代码似乎运行得很好。

Now, I just dropped in a button - you click on it, and it does load the other page into the div - but you can have that js code run on page load - say document ready, or even just place the above code in the script not wrapped in a function.现在,我只是放入一个按钮 - 你点击它,它确实将另一个页面加载到 div - 但是你可以在页面加载时运行该 js 代码 - 说文档准备好,或者甚至只是将上面的代码放在脚本未包装在函数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM