Krish Chandra
Krish Chandra

Reputation: 11

Button Click outside of an UpdatePanel causes the panel to refresh

I have a default VS 2013 ASP.NET Webform project with a master page containing a ScriptManager and a content page containing an UpdatePanel. This is what I have inside the ContentPlaceHolder of the content page:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            Updated at: <%=DateTime.Now.ToString() %>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Button Text="Click" runat="server" />
</asp:Content>

Everytime I click the 'Click' button, the time inside the UpdatePanel gets refreshed, even when I set the UpdateMode to 'Conditional'.

My understanding is that the ASP.NET code to display the time should get executed only the first time I GET the page and subsequently by any triggers defined for the panel(as the update mode of the panel is conditional).

Am I wrong? If so, why?

Upvotes: 0

Views: 3693

Answers (1)

Amarnath Balasubramanian
Amarnath Balasubramanian

Reputation: 9460

The Button should be placed inside the other update panel.

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        Updated at: <%=DateTime.Now.ToString() %>
                    </ContentTemplate>
                </asp:UpdatePanel>
             <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                      <asp:Button ID="Button1" Text="Click" runat="server" />
                    </ContentTemplate>
                </asp:UpdatePanel>

            </asp:Content>

Hope it helps,

And to know more about update panel please visit the link

http://ajax.net-tutorials.com/controls/updatepanel-control/

Upvotes: 2

Related Questions