您可以在 .NET 中异步更改母版页的 ContentPlaceHolder 的内容页吗?

发布于 2024-07-12 22:31:06 字数 344 浏览 5 评论 0原文

从我已经读过的内容来看,这似乎是不可能的,但我想看看是否有人有秘密的伎俩,或者至少是明确的“不”。

据说母版页实际上只是内容页使用的控件,而不是内容页的“母版”。 如果我想从一个内容页面转到具有相同母版页的另一个内容页面,我只会说

Response.Redirect("PageB.aspx");

但这会立即导致回发,使页面闪烁,这是蹩脚的 pre-ajax 处理方式。

在当前的项目中,我试图看看是否可以弄清楚当单击母版页上的按钮时如何异步更改母版页中 ContentPlaceHolder 的当前内容页面。

这可能吗,如果可以的话怎么办?

From what I've already read this appears to be impossible, but I wanted to see if anyone out there has a secret trick up their sleeve or at least a definitive "no".

Supposedly a master page is really just a control for a content page to use, not actually the "master" of a content page. If I wanted to go from one content page, to another content page with the same master page, I would just say

Response.Redirect("PageB.aspx");

But this would immediately cause a postback, flickering the page, which is the crappy pre-ajax way of doing things.

In this current project, I'm trying to see if I could figure out how to change the current content page of a ContentPlaceHolder in the master page asynchronously, when a button is clicked on the master page.

Is this possible, if so how?

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

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

发布评论

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

评论(2

維他命╮ 2024-07-19 22:31:06

我不知道是否可以在页面(.aspx)之间进行切换,但绝对可以使用用户控件来完成。

每个 ASP.Net 页面都有自己的 URL,因此您要做的就是从一个 URL 转到另一个 URL,而不进行任何回发,这不是它应该如何工作的。


使用用户控件 (.ascx):

创建一个使用 MasterPage 的页面,并在内容中使用类似的内容

<ajax:UpdatePanel ...>

    <ContentTemplate>

        <asp:PlaceHolder ...>

    </ContentTemplate>

</ajax:UpdatePanel>

搜索 UpdatePanel 并调整其设置以执行您想要的操作,然后了解如何交换用户控件在占位符中。

I don't know if you can between pages (.aspx) but it can definitely be done using UserControls.

ASP.Net pages each have their own URL so what you're trying to do is to go from one URL to another without any postback, that's just not how it's supposed to work.


Using user controls (.ascx):

Create a page that uses the MasterPage and use something like this in the content

<ajax:UpdatePanel ...>

    <ContentTemplate>

        <asp:PlaceHolder ...>

    </ContentTemplate>

</ajax:UpdatePanel>

Search for UpdatePanel and tweak its settings to do what you want, then learn how to swap user controls in a placeholder.

攀登最高峰 2024-07-19 22:31:06

,您不能,因为母版页实际上是在特定 aspx 页面上呈现的控件,而不是实际包含 aspx 页面,因为它在设计视图中看似以编程方式呈现。

更多信息

不过,您可以使用各种其他控件来模拟此效果。 asp:MultiView 控件就是一个示例,每个“页面”都可以在单个视图中制作并放置在更新面板中,从而允许其异步切换。 或者,您可以在单独的用户控件中定义每个页面,并将其放入更新面板中,根据需要异步切换这些控件上的可见属性。

实际上有很多不同的方法可以实现类似于更改母版页的内容占位符的效果。

No, you cannot because a master page is actually a control rendered on a particular aspx page, rather than actually containing the aspx page as it deceptively appears to be programmatically and in design view.

More Info:

You could however use a variety of other controls to simulate this effect. The asp:MultiView control is one example, each "page" could be made in a single view and placed in an update panel, thus allowing it to be switched asynchronously. Alternatively you could define each page in a separate user control and put those in an update panel, asynchronously switching the visible property on those controls as needed.

There are really a lot of different ways to achieve an effect similar to changing the master page's content placeholder.

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