简体   繁体   English

如何在特定的另一个 aspx 页面中加载一个 aspx 页面<div>标签</div><div id="text_translate"><p>我想用来自另一个 *.aspx 页面的内容更新页面的某个部分,从而避免只有一个(非常)长的代码页面。</p><p> 所以:如何在特定标签中的另一个 aspx 页面中加载一个 aspx 页面,而不必重新加载整个页面。</p></div>

[英]How can I load an aspx page in another aspx page in a specific <div> tag

I would like to update a certain part of the page with content from another *.aspx page, thus avoiding having to have just one (very) long page of code.我想用来自另一个 *.aspx 页面的内容更新页面的某个部分,从而避免只有一个(非常)长的代码页面。

So: How can I load an aspx page in another aspx page in a specific tag, without having to reload the entire page.所以:如何在特定标签中的另一个 aspx 页面中加载一个 aspx 页面,而不必重新加载整个页面。

You need to use AJAX.您需要使用 AJAX。

You can either put an ASP.Net UserControl in an <asp:UpdatePanel> , or (preferably) use jQuery.load您可以将 ASP.Net UserControl 放在<asp:UpdatePanel>中,或者(最好)使用jQuery.load

If you are using Webforms (and it sounds like you are), you might want to look into User Controls (ascx pages).如果您正在使用 Webforms(听起来确实如此),您可能需要查看用户控件(ascx 页面)。 If you are using MVC, consider a Partial View.如果您使用的是 MVC,请考虑使用局部视图。

Use a web control.使用 web 控件。 That way its all inside there and reusable.这样它就在里面并且可以重复使用。

If you want to load the content after the initial page has loaded, you can use jQuery's ajax() method to load up that page and store the result in the div you want.如果要在初始页面加载后加载内容,可以使用jQuery 的 ajax()方法加载该页面并将结果存储在所需的 div 中。 Otherwise, putting your code in a web control and placing that control on the page will work.否则,将您的代码放在 web 控件中并将该控件放在页面上将起作用。

I think conceptually you're going about this with the wrong approach.我认为从概念上讲,您正在使用错误的方法来解决此问题。 Besides avoiding a very long page of code, what are you trying to accomplish?除了避免一页很长的代码之外,您还想完成什么? There are many ways to pull code out of a class, without necessarily touching your display code.有很多方法可以从 class 中提取代码,而不必触摸您的显示代码。 Also try ASP.Net web controls, as they allow you to have reusable view objects.还可以尝试 ASP.Net web 控件,因为它们允许您拥有可重用的视图对象。

If you're interested in refreshing the page in pieces, look at AJAX.如果您对刷新页面感兴趣,请查看 AJAX。

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

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