One update panel updated and other one is also updated?

2.2k views Asked by At

I have scenario, I have two update panels on the page (both have update mode='conditional'). If I update one update panel the other is automatically updated. This is first problem.

I am using UpdatePanelAnimationExtender. If one update panel is updated, that don’t have updatepanelAnimationExtender other one also updated and that have updatepanelAnimationExtender, OnUpdatingUpdatePanel(); event is fired. As the documentation of updatepanelAnimationExtender says: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/UpdatePanelAnimation/UpdatePanelAnimation.aspx

OnUpdating - Generic animation played as when any UpdatePanel begins updating

OnUpdated - Generic animation played after the UpdatePanel has finished updating (but only if the UpdatePanel was changed)

Problem: OnUpdating fired and it worked backend and not finished because onUpdated only fired when an UpdatePanel Changed

2

There are 2 answers

0
Roopesh Shenoy On BEST ANSWER

"Add 2 update panel on page, set updatemode='conditional' for both and add load event for both updatepanel and set breakpoint for both load event and add 1 button and then add Asyn trigger for button click on 1 update panel.... you will notice when you hit button, it should load only triggered update panel and 2nd one remain unchanged, but 2nd updatepanel is load event also fired"

This will happen only if the button is inside the 2'nd updatepanel? If not, then I dont think it will update the second update panel. Could you confirm if the button is inside or outside the second updatepanel?

0
Sheldon Cooper On

I just had this same issue. Two update panels on the same page that are NOT nested and have UpdateMode="Conditional". Just realize that when one update panel on a page triggers a partial postback, all update panels will get the updating event triggered. If you have an UpdatePanelAnimationExtender hooked up to UpdatePanel A, and a partial postback is triggered for an unrelated UpdatePanel B, both will get the updating event triggered, and the animation for UpdatePanel A will only run the OnUpdating part and not the OnUpdated part (so basically the animation will run half way).

This is how I fixed this issue: Determine which update panel was triggered. This can be found by getting the value of the form variable for the script manager. The update panel in question will be mentioned in the string. Use this info to perform an action based on your needs.

// Variable to hold ScriptManager.  Just slap this in the class for the page.
private ScriptManager scriptManager;

// Get the ScriptManager.  Put this in Page_Init handler.
// If you have the ScriptManager on the same page, just refer to it directly.
// If you have it on the master page, you can get a reference to it like so.
// The second line shows one way you can get a reference to the ScriptManager from
// a user control.
// FYI, the same code applies to a ToolkitScriptManager.
scriptManager = ScriptManager.GetCurrent(this);
// scriptManager = ScriptManager.GetCurrent(HttpContext.Current.Handler as Page);

// This function checks whether an UpdatePanel is being updated
private Boolean IsUpdatePanelUpdating(String sUPID)
{
    String sUpdateValue = Request.Form[Request.Form.AllKeys.Where(s => s.EndsWith(scriptManager.ClientID)).FirstOrDefault()] ?? String.Empty;
    return sUpdateValue.Contains(sUPID);
}

// This is code you can put somewhere (say within OnLoad handler) to make an
// UpdatePanel A get updated even if an unrelated UpdatePanel B is currently being
// updated.
if (!IsUpdatePanelUpdating(upA.ClientID))
    upA.Update(); 

I hope this helps someone.