An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

Wednesday, May 16, 2007 7:50 AM

We saw about Update Panel and how it works in its simplest form.  Let us explore more complex scenarios where we have multiple Update Panels, Nested Update Panels, etc.,

One of the main properties of an UpdatePanel is its UpdateMode property.  The UpdateMode property is by default set to "Always".

However, when you have more than a single update panel or when you want to control as to when the Update Panel needs to get refresh, then setting the UpdateMode property to "Condition" is the first step.

Let us consider a scenario where we have 4 Update Panels in a page.  For simplicity I am sticking to the Label - Display Current Date functionality.  The HTML for the same is as below:-

 <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
   
    <div>
        <table width="100%">
            <tr>
            <td style="height: 64px">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            <b><u>Section 1</u></b>
            <br />
            <br />
            <asp:Label ID="Label1" runat="server"></asp:Label>
            <br />
            <br />
            <asp:Button ID="Button1" runat="Server" Text="Refresh" OnClick="Button1_Click" />
           
           
            </ContentTemplate>
           
            </asp:UpdatePanel>
           
            </td>
            <td style="height: 64px">
            <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            <b><u>Section 2</u></b>
            <br />
            <br />
                        <asp:Label ID="Label2" runat="server"></asp:Label>
            <br />
            <br />
            <asp:Button ID="Button2" runat="Server" Text="Refresh" OnClick="Button2_Click" />
           
           
            </ContentTemplate>
           
            </asp:UpdatePanel>
           
            </td>
            <td style="height: 64px">
            <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            <b><u>Section 3</u></b>
            <br />
            <br />
                        <asp:Label ID="Label3" runat="server"></asp:Label>
            <br />
            <br />
            <asp:Button ID="Button3" runat="Server" Text="Refresh" OnClick="Button3_Click" />
           
           
            </ContentTemplate>
           
            </asp:UpdatePanel>
           
            </td>
            <td style="height: 64px">
            <asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <b><u>Section 4</u></b>
            <br />
            <br />
                        <asp:Label ID="Label4" runat="server"></asp:Label>
            <br />
            <br />
            <asp:Button ID="Button4" runat="Server" Text="Refresh" OnClick="Button4_Click" />
           
           
            </ContentTemplate>
           
            </asp:UpdatePanel>
            </td>
            </tr>
       
       
        </table>
   
    </div>
    </form>

 Note that for all the UpdatePanels, I have set the UpdateMode to conditional.  The application logic or codebehind for the above is as follows:-

 protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = System.DateTime.Now.ToString();
        Label2.Text = System.DateTime.Now.ToString();
        Label3.Text = System.DateTime.Now.ToString();
        Label4.Text = System.DateTime.Now.ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {

    }
    protected void Button3_Click(object sender, EventArgs e)
    {

    }
    protected void Button4_Click(object sender, EventArgs e)
    {

    }

When you run this page, you will notice that there are four Sections - Section 1, 2,3 & 4.  When you click on the Refresh button, the date time value gets refreshed only for the particular section.  The other values doesnt get changed.

If you remove the UpdateMode=Conditional from the above UpdatePanel declarations, you will notice that all the labels get refreshed.

Hence, setting the UpdateMode as Conditional is important if you like to control the way the UpdatePanels get refreshed.

Next, we will explore the Nested UpdatePanel example.

Cheers !!!


Feedback

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

Thanks a lot,

For giving a good things about Update Panel

Thanks,
Manoaranjan 12/22/2007 12:49 AM | gggggggggggggg

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

hhhhhhhhhhhhhhhhhhhhhhh 12/26/2007 9:05 PM | hjhgj

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

if u are using an update progress for each update panel and don't want them all triggered on postback, us the AssociatedUpdatePanelID for the update progress

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Loading... </ProgressTemplate>

</asp:UpdateProgress> 1/15/2008 10:27 PM | VA Internet

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

Hi author,
thanks for nice article.
But Now I have one problem.When I run my application(code),the event for button is not generated.same for link button also.--javascript error comes on status bar.
What is the solution?
Please help the needful. 2/5/2008 1:00 AM | mahesh

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

Thanks a lot buddy!
This was a very valuable Information... 2/16/2008 5:29 PM | Subodh

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

I have a page with multiple update panels and each ones updatemode is set to conditional and update method for each panel is called explicitly. But the panel doesnt seem to update itself after every postbacks.
What else should I do?? 3/20/2008 3:10 AM | Amulu

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

found ur article helpful.i hv a problem in my proj
on the click of 1 image button other image buttons and panel must not be refreshed.hw can i do this.all this is in the same page.can u help me?? 4/1/2008 5:52 PM | shweta

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

Thanks a lot buddy!! Good info about update panel 7/10/2008 1:09 AM | Abdul Aziz

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

Thanks for sharing pal.
really nice one.. 7/20/2008 11:31 PM | srilatha

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

Thanks for the info nicley done... 9/12/2008 7:55 AM | jhon

# re: ASP.NET 2.0 AJAX Extensions Update Panel - Multiple Update Panels

I have a user control that I am dynamically adding to a form. When I add more than one instance of it I have the following issue: Upon clicking the button within the first instance of the control, the second instance get's the update. The update panel does have conditional update specified and the button is within the update panel. The Page_Load event in the code beind makes no distinction between instances of the control. In fact all it does is re-add the control to the form. The content of the panel is only populated if the event is not a post-back. I'm relatively new to the ASP.NET AJAX arena and I'm obviously not taking something into account.
Any feedback would be greatly appreciated.
Jerry 11/16/2008 10:04 PM | Jerry Bailey

Post a comment





 

Please add 5 and 4 and type the answer here: