I have an ASP.Net Update Panel which contains controls that I am trying to update from the code-behind file by setting the value of the controls to whatever I want them to be, and then calling the Update() method of the UpdatePanel.
I know that to call the Update() method, I need to set the UpdateMode property to conditional so this is what I have done, but I am getting the following error regardless:
The Update method can only be called on UpdatePanel with ID ‘UpdatePanel1’ when UpdateMode is set to Conditional.
My Properties box looks like this:

My code looks like this:
using System;
using System.Timers;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var myTimer = new System.Timers.Timer();
myTimer.Interval = 1000;
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
myTimer.Start();
}
void myTimer_Elapsed(object sender, ElapsedEventArgs e)
{
var newGUID = Guid.NewGuid().ToString();
Label1.Text = newGUID;
UpdatePanel1.Update();
}
}
}
My form looks like this:

My Markup is below:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#form1
{
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" style="text-align: center" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
Why isn’t this working?
Thanks
I would recommend you checking the following tutorial. The Timer control used is a
System.Web.UI.Timerand not aSystem.Timers.Timeras in your code. Also the timer must be placed inside the update panel in order for it to trigger an AJAX call when theOnTickevent is triggered: