简体   繁体   English

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

[英]Can you change a master page's ContentPlaceHolder's Content Page Asynchronously in .NET?

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. 但这会立即导致回发,从而使页面闪烁,这是糟糕的预ajax处理方式。

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. 在此当前项目中,我试图查看当单击母版页上的按钮时,是否可以找出如何异步更改母版页中ContentPlaceHolder的当前内容页的方法。

Is this possible, if so how? 如果可能的话,这可能吗?

I don't know if you can between pages (.aspx) but it can definitely be done using UserControls. 我不知道是否可以在页面(.aspx)之间进行切换,但是绝对可以使用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. 每个ASP.Net页面都有其自己的URL,因此您要尝试的是从一个URL转到另一个URL而没有任何回发,这不是应该的工作方式。


Using user controls (.ascx): 使用用户控件(.ascx):

Create a page that uses the MasterPage and use something like this in the content 创建一个使用MasterPage的页面,并在内容中使用类似的内容

<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. 搜索UpdatePanel并调整其设置以执行所需的操作,然后学习如何在占位符中交换用户控件。

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. ,您不能这样做,因为母版页实际上是在特定aspx页上呈现的控件,而不是实际上包含aspx页,因为它看起来像是在程序设计和设计视图中。

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. asp:MultiView控件是一个示例,每个“页面”都可以在单个视图中创建并放置在更新面板中,从而可以异步切换它。 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. 或者,您可以在单独的用户控件中定义每个页面,然后将它们放在更新面板中,根据需要异步切换这些控件上的visible属性。

There are really a lot of different ways to achieve an effect similar to changing the master page's content placeholder. 与更改母版页的内容占位符类似,实际上有很多不同的方法可以实现效果。

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

相关问题 我可以知道母版页的ContentPlaceHolder中的哪个页吗? - Can I know what page is in my master page's ContentPlaceHolder? 母版页中contentplaceholder之外的更新面板导致回发到内容页 - An updatepanel outside of contentplaceholder in master page causes post back to content page 如何在运行时更改页面的母版页? - How can I change my page's Master Page at runtime? 内容页面找不到ContentPlaceHolder&#39;ContentPlaceHolder1&#39; - Content page cannot find ContentPlaceHolder 'ContentPlaceHolder1' 如何识别Timer的回调(定时器在主页面中)在主页面和内容页面中 - how can recognize Timer's callback (Timer Is In Master Page) In both Master & Content Page 如何在母版页后面的代码中访问Telerik RadEditor控件(嵌入在“内容”页中)? - How do you access Telerik RadEditor control (embedded in Content page) in master page's code behind? 如何在asp.net的内容页面的更新面板中获取母版页控件 - How to get master page control in content page's update panel in asp.net C#asp.net-如何从母版页访问内容页的方法? - C# asp.net- How to access content page's method from master page? 动态更改ContentPlaceHolder的内容 - Changing ContentPlaceHolder's content dynamically 如何在主页面上声明的内容页面的代码后面重新定义变量? - How to redefine a variable on content page's codebehind that was declared on master page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM