简体   繁体   English

在 Asp.Net AJAX 的嵌套 UpdatePanel 中区分 AsyncPostbacks

[英]Making a difference between AsyncPostbacks in nested UpdatePanels in Asp.Net AJAX

In an ASP.net AJAX project (WebForms), I have an UpdatePanel, and in UpdatePanel I have multiple nested Controls with UpdatePanels, basically I have control trees.在 ASP.net AJAX 项目 (WebForms) 中,我有一个 UpdatePanel,在 UpdatePanel 中,我有多个带有 UpdatePanel 的嵌套控件,基本上我有控件树。

The Parent Control is huge and very important part of the site.家长控制是网站的一个巨大且非常重要的部分。 I cannot touch it, (and also it is reused on many places), the UpdatePanel should remain in its current position.我无法触摸它(而且它在很多地方都被重复使用),UpdatePanel 应该保持在当前位置。

The child controls in the update panel have functionality's which are separated from each other(also they are separated with UpdatePanel), to be able to refresh just a piece from a control.更新面板中的子控件具有彼此分离的功能(它们也与 UpdatePanel 分离),以便能够仅刷新控件的一部分。

Basically on Page_Load() I have code which fulfills every Child control with data, for instance if I have a delete functionality which is modifying the child controls data.基本上在 Page_Load() 上,我有代码用数据来满足每个子控件,例如,如果我有一个正在修改子控件数据的删除功能。 The steps are like this:步骤是这样的:

First showing the control (ParentControl).首先显示控件(ParentControl)。

  • Page_Load() -> Fullfill data Page_Load() -> 填充数据

If I click on delete:如果我点击删除:

  • Page_Load() -> fullfill data /* Don't want do invoke this here! Page_Load() -> fullfill data /* 不想在这里调用它! */ */

  • event Delete ->modify data事件删除->修改数据

     ->fullfill data again!

I need to make a programmatical difference on AsyncPostbacks ,and use on Page_Load() function to not invoke the fulfill data when you just want to perform an event.我需要在AsyncPostbacks上进行编程差异,并在 Page_Load() 函数上使用以在您只想执行事件时不调用 fulfill 数据。

Outside UpdatePanel you can use IsAsyncPostback , IsCallBack , IsPostback I know this for sure, but these properties don't change on AsyncPostback .在 UpdatePanel 之外,您可以使用IsAsyncPostbackIsCallBackIsPostback我肯定知道这一点,但这些属性在 AsyncPostback 上不会改变

I have 2 AsycPostbacks and I need to make differentiate between them.:我有 2 个 AsycPostbacks,我需要区分它们。:

  1. First this just showing data and initialize.首先,这只是显示数据和初始化。
  2. Perform an event and making modifications on control执行事件并修改控件

Have somebody know a technique to implement, or some sort of Framework which is having this type of functionality?有人知道一种实现技术或某种具有此类功能的框架吗?

Does anybody have this problem?有人有这个问题吗?

I've deleted my other answer - seeing as you're now describing a completely different problem to the initial one, and it seemed foolish to completely replace my answer, while keeping the rep for the previous version.我已经删除了我的另一个答案 - 看到你现在描述的是一个与最初的问题完全不同的问题,完全替换我的答案似乎是愚蠢的,同时保留以前版本的代表。

You're going to have to check either the events causing the asynchronous call backs, or check for some value of the controls in each of the update panels to help you work out what's changed.您将不得不检查导致异步回调的事件,或者检查每个更新面板中控件的某些值,以帮助您确定更改的内容。

This is one of the key reasons I decided not to use update panels, the asynchronous post-back causes almost all of the page life-cycle events to happen, and makes it very hard to actually see what's happening in complex situations like this - the only time I've used an update panel in anger was on my personal site to wrap around a data grid to save the whole page reload when working with large sets of data.这是我决定不使用更新面板的关键原因之一,异步回发导致几乎所有页面生命周期事件发生,并且很难真正看到在这种复杂情况下发生了什么 -只有一次我愤怒地使用更新面板是在我的个人网站上环绕数据网格以在处理大量数据时保存整个页面重新加载。


Edit to add:编辑添加:

Just trying to help, a quick google turned up this (AJAX and the ASP.NET 2.0 Callback Framework) :只是想帮忙,一个快速的谷歌出现了这个(AJAX 和 ASP.NET 2.0 回调框架)

Which control initiated the request?哪个控件发起了请求?

In the postback request, the ScriptManager id operates as the parameter.在回发请求中,ScriptManager id 作为参数运行。 In general, the value is the id of the control that initiated the partial postback.通常,该值是发起部分回发的控件的 id。 It is in the format |.它的格式是|。 Controls can register with the ScriptManager directly or via an UpdatePanel.控件可以直接或通过 UpdatePanel 向 ScriptManager 注册。 The ScriptManager.AsyncPostBackSourceElementID property will return the id of the control that initiated the partial postback. ScriptManager.AsyncPostBackSourceElementID 属性将返回启动部分回发的控件的 ID。

Example syntax:示例语法:

ScriptManager1=UpdatePanel1|Button1

That page also goes into some detail about the life cycle, and various hooks into the process.该页面还详细介绍了生命周期以及流程中的各种挂钩。

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

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