Ajax – Update mode property of UpdatePanel

ajaxasp.netupdatepanel

Following is my ASPX code.

<form id="form1" runat="server">
  <div>
   <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   <asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel1" runat="server">
   <ContentTemplate>
     <asp:Label ID="lblid" runat="server" Text="Label"></asp:Label>
   </ContentTemplate>
   </asp:UpdatePanel>
   <asp:Button ID="btnid" runat="server" Text="Button"/>
  </div>
</form>

I have one update panel control and have included single lable control inside the update panel control. I have Button and Lable outside the update panel control and during page_load I update the the text value of both the lable control as follows.

protected void Page_Load(object sender, EventArgs e)
{
  lblid.Text = DateTime.Now.ToString();
  Label1.Text = DateTime.Now.ToString();
}

I have set Update mode property to 'Conditional' so that when Button control outside the Update panel is clicked by user, It should not change the text value of lable inside the ipdate panel. But it update and diplay the changed value of label text inside the update panel. My understanding is that when we set update mode property to 'Conditional', content inside the update panel is not updated(or rendred on client side) when there is a postback due to control outside the update panel then what is happening in my case.

Best Answer

Clicking the button outside of UpdatePanel is causing the entire page to postback. An UpdatePanel can't prevent the contents inside it from being refreshed in the case the when entire page is being posted-back.

Related Topic