ASP.NET 中的母版页和回发
我们如何避免母版页回发整个页面?
How can we avoid Master Page from posting back the whole page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我们如何避免母版页回发整个页面?
How can we avoid Master Page from posting back the whole page?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
只是为了澄清 - 更新面板不会阻止整个页面回发或整个页面生命周期。 它只会导致该过程在用户“看不见”的后台完成。 唯一的区别是,回发完成后,仅刷新更新面板声明所包含的部分,从而导致仅回发页面的一部分的错觉。
如果触发器控件位于 updatepanel 内部,则应将 ChildrenAsTriggers 属性设置为 True。 如果触发更新的控件位于更新面板之外,那么您应该将触发器部分添加到控制面板并添加异步触发器。 如果是组合,那么可以将两者结合起来以获得最佳效果。
如果触发更新的控件包含在更新面板内:
或者如果该控件不包含在更新面板内:
Just to clarify - the update panel doesn't prevent a whole page postback or a full page lifecycle. It just causes that process to be completed in the background "unseen" to the user. The only difference is that upon completion of the postback only the section wrapped by the update panel declaration is refreshed, thus causing the illusion that only part of the page is posted back.
If the trigger control is inside the updatepanel then you should set the ChildrenAsTriggers attribute equal to True. If the control that triggers the update is outside the update panel, then you should add the Triggers section to the control panel and add an asynchronous trigger. If it is a combination, then you could combine the two for the best effect.
If the control that triggers the update is contained inside the update panel:
Or if the control isn't contained inside the update panel:
使用母版页实际上对整个页面是否回发没有任何影响。 没有母版和标准的简单 ASPX 页面也可以进行整个页面回发。
不过,从字里行间看,我猜您的母版页上已经有一些 UpdatePanel(可能围绕内容占位符),当其中的某些内容导致回发时,它们会阻止整个页面刷新。
无论哪种方式,防止全页刷新(无论是否使用母版页)的关键是确保导致回发的控件位于 UpdatePanel 内,或使用某些 JavaScript 回调服务器并异步处理响应。
Using a master page doesn't really have any effect on whether the whole page posts back or not. A simple ASPX page with no master and a standard would do a whole page postback too.
Reading between the lines though, I'm guess that your master page has some UpdatePanels on it already (perhaps surrounding the content placeholders) that prevent the whole page from refreshing when something inside them causes a postback.
Either way, the key to preventing a full page refresh (whether using master pages or not) is to make sure that the control that causes the postback lives inside an UpdatePanel or use some JavaScript to call back to the server and process the response asynchronously.
母版页不负责回发,而 HTML 表单则负责回发。
阻止页面回发的唯一方法是将整个内容包装在 UpdatePanel 中。 但这本身就是一个非常糟糕的主意!!
The Master Page isn't responsible for the PostBack, that's what the HTML form is for.
The only way you could prevent a page from posting back would be to wrap the entire thing in an UpdatePanel. But that itself is a really bad idea!!