Monday, March 15, 2021

Remember to set UpdatePanel's UpdateMode to Conditional


UpdateMode property of the UpdatePanel


Since the cool thing about the ASP.NET Ajax UpdatePanel is that its contents are updated asynchronously when an event that would normally generate a postback is raised inside, one would think that this is its default behavior.
But it's not: the UpdateMode property of the UpdatePanel has 2 possible values:
  • Always
  • Conditional
and the default value is Always.

  • When set to Always, the UpdatePanel is updated on every postback raised from anywhere in the page, so from controls inside the panel, inside other panels or just on the page.
  • When set to Conditional, the UpdatePanel will be updated only on postback originated by controls inside the panel or from the triggers specified.
So, if you have multiple update panels and you don't want to update all of them to be updated every time, you have to set the UpdateMode to Conditional:

<asp:UpdatePanel ID="UpdatePanel1" 
                  UpdateMode="Conditional"
                  runat="server">

No comments: