ASP.NET 2.0 AJAX Extensions Update Panel - Nested Update Panel

If you have been following my articles, you would have realised how easy it is to implement partial page refreshing in ASP.NET AJAX where we explored a single UpdatePanel and multiple Update Panel examples.

Let us now consider a more complex scenario where we want to nest Update Panels.

Page

       UpdatePanel 1 (Parent)

            UpdatePanel 2 (Child)

The thumb rule with nested update panels is as follows:-

Parent Update Panel refreshes all the contents including Child Update Panel's contents even if the Child Update Panel's update mode is set to Conditional

Child Update Panel refreshes only its contents and doesnt refresh that of the Parent Update Panel unless, the update mode for the parent update panel is not set to Conditional

Kind of confusing eh?  Let us see it in action.  Copy paste the following HTML and the subsequent source code to see it in action.

 <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div>
            <table width="80%" border="3">
                <tr>
                    <td>
                        Label outside all the Update Panels
                        <asp:Label ID="Label3" runat="Server" Font-Bold="true"></asp:Label>
                        <br />
                        <br />
                        <asp:Button ID="Button3" runat="Server" Text="Refresh" />
                        <br />
                        <br />
                    </td>
                </tr>
                <tr>
                    <td>
                        <table width="65%" border="2">
                            <tr>
                                <td>
                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>
                                            Label within the Parent Update Panel
                                            <asp:Label ID="Label1" runat="server" Font-Bold="true"></asp:Label>
                                            <br />
                                            <br />
                                            <asp:Button ID="Button1" runat="server" Text="Refresh" />
                                            <table width="40%" border="1">
                                                        <tr>
                                                        <td>
                                                       
                                                       
                                                        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                                                <ContentTemplate>
                                                    <br />
                                                    <br />
                                                   
                                                    Label within the Child Update Panel
                                                    <asp:Label ID="Label2" runat="server" Font-Bold="True"></asp:Label>
                                                    <br />
                                                    <br />
                                                    <asp:Button ID="Button2" runat="server" Text="Refresh" />
                                                </ContentTemplate>
                                            </asp:UpdatePanel>
                                                        </td>
                                                       
                                                        </tr>
                                                   
                                                    </table>
                                           
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
    </form>

Code behind

  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();
    }

When you run the above page, you will notice that I have put nice looking (??) tables to clearly indicate the label outside the Update Panels, the parent update panel contents and the child update panel contents.

When you click on the top most button, it refreshes the whole page and subsequently, all the labels get refreshed with the new date time.

However, when you click on the second refresh button which is marked inside the Parent Update Panel you will notice that the top most label doesnt get refreshed but both the Label 2 and Label 3 gets refreshed, although I have marked UpdateMode as conditional for the Child UpdatePanel.  The reason being, the parent updates all the child update panels nested within.

Finally, when you click on the last Refresh button which is marked inside the Child Update Panel, you will notice that only the respective label gets refreshed.

Note that, if I remove the property UpdateMode=Conditional for the UpdatePanel1 (parent), both the labels will get refreshed.

Enough of Update Panels eh?

Cheers !!!

 

 

posted @ Wednesday, May 16, 2007 8:05 AM

Print

Comments on this entry:

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

Left by asim at 2/5/2008 11:03 PM
Gravatar
nice one...simple as well..helps beginners of ajax a lot...thanks

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

Left by shobhit madhuni at 4/1/2008 12:12 AM
Gravatar
Good one.

Easy to understand

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

Left by con cac at 4/2/2008 3:28 PM
Gravatar
nice article :)
Thanks a lot.

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

Left by Asim Suvedi at 4/26/2008 10:41 PM
Gravatar
Its nice and easy to understand but would have been better if u had also used triggers for each update panels. That would confuse the readers about why the triggers are missing here??

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

Left by Mike at 5/29/2008 9:29 AM
Gravatar
This was helpful. Thanks!

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

Left by dmitry at 6/13/2008 10:57 PM
Gravatar
good article

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

Left by hash at 6/18/2008 1:54 AM
Gravatar
nice artical. Can you tell me why update panel is not working in master pages ?

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

Left by Barbaros at 10/10/2008 5:56 PM
Gravatar
Great
Thanks

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

Left by Andy at 10/23/2008 8:13 PM
Gravatar
we need a lot more of these type of articles on the web! thanks so much.

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

Left by Anubhav Goyal at 12/16/2008 11:09 AM
Gravatar
great post. simple example but very efficient

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

Left by A. Soong at 1/7/2009 5:40 AM
Gravatar
Nice one - thank you!

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

Left by jeyaraj at 1/22/2009 9:31 AM
Gravatar
This articles was very useful for beginners of ajax. thanks lot.

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

Left by bunty at 2/26/2009 12:53 PM
Gravatar
gr8 job dude

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

Left by bunty at 2/26/2009 12:54 PM
Gravatar
mind blowing mogyambo khush hua

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

Left by Mike at 3/12/2009 10:40 PM
Gravatar
Great article.

You totally confused me with:
"Child Update Panel refreshes only its contents and doesnt refresh that of the Parent Update Panel unless, the update mode for the parent update panel is not set to Conditional"

When you could have written:
"Child update panel refreshes only it's contents and doesn't refresh that of the parent if the parent's UpdateMode is set to Conditional."

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

Left by Mike at 3/12/2009 10:40 PM
Gravatar
Great article.

You totally confused me with:
"Child Update Panel refreshes only its contents and doesnt refresh that of the Parent Update Panel unless, the update mode for the parent update panel is not set to Conditional"

When you could have written:
"Child update panel refreshes only it's contents and doesn't refresh that of the parent if the parent's UpdateMode is set to Conditional."

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

Left by Vinoth Kannan S at 4/3/2009 2:28 PM
Gravatar
Nice Post. Its very useful to me.

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

Left by Selvi at 6/2/2009 8:36 PM
Gravatar
Its very nice article

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

Left by Jason Chmiel at 6/18/2009 11:11 AM
Gravatar
This is a very good article but I do have one problem that it didn't address, although you may be able to. This is showing updates using two buttons, but is there a way to only update the parent updatepanel if a form is fully filled out, else it only updates the child updatepanels? I can't find any articles that will address this so it may not be possible but I pray it is!

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

Left by subodh at 6/20/2009 5:17 AM
Gravatar
Very good article

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

Left by Trendra at 6/30/2009 3:20 AM
Gravatar
This is good article but i have one problem if parent have a validator control and try to update child panel and click button inside child panel then first off all parent validator called. but I don't want this.

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

Left by Scott at 7/23/2009 9:19 PM
Gravatar
Superb article! I managed to try it out and published my site at my current host (ASPHostCentral.com) and it is just working perfectly fine.

I do, however, expect a slightly more complicated article. I am now tring the latest ASP.NET MVC and I am still learning. My current host supports this framework so it is truly a great chance for me to learn ASP.NET MVC as well.

All the best!

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

Left by Preetham at 7/31/2009 2:35 PM
Gravatar
Yo man,, Nice Work,, Keep Going,,

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

Left by nani at 8/19/2009 12:24 AM
Gravatar
nice article...

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345