0
Answer

can not build timer into update panel in c#

william jones

william jones

14y
11.4k
1

I am trying to add a timer control into an update panels content template. I can do this under the web design using the following ( example 1) so that it will only update the panel that it is in.
when I try to build it under c# using the following ( example 2) it will not build the timer into the update panel so it updates the entire page.
Im new to c# so this is a extreme learning curve! every spare minute is spent  doing a lot of online reading and training!
example 1
<
body>
<form id="Form1" runat="server">
<
<asp:ScriptManager ID="CitySystemScript" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="CitySystemPanel" runat="server">
<ContentTemplate>
<asp:Timer ID="cityTimer" runat="server" Interval="30000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
example 2

// Build the scriptmanager to activate the asp page
ScriptManager scriptmanager = new ScriptManager();
scriptmanager.ID =
"scriptmanager1";
form1.Controls.Add(scriptmanager);
// Create Panel to hold sites
Panel CitySystemPanel = new Panel();
CitySystemPanel.Style.Add(
HtmlTextWriterStyle.Position, "absolute");
CitySystemPanel.Style.Add(
HtmlTextWriterStyle.Height, "200px");
CitySystemPanel.Style.Add(
HtmlTextWriterStyle.Width, "600px");
CitySystemPanel.Style.Add(
HtmlTextWriterStyle.Left, "1px");
CitySystemPanel.Style.Add(
HtmlTextWriterStyle.Top, "1px");
form1.Controls.Add(CitySystemPanel);
/* ---------------------------------------------------------------------------*/
// Labeling for the panel
Label CitySystemTitle = new Label();
CitySystemTitle.Text =
"City System";
CitySystemTitle.CssClass =
"systemname33xx";
CitySystemTitle.Style.Add(
HtmlTextWriterStyle.Width, "720px");
CitySystemPanel.Controls.Add(CitySystemTitle);
/* ---------------------------------------------------------------------------*/
// Create update container for Ajax
UpdatePanel CitySystemUpdatePanel = new UpdatePanel();
CitySystemUpdatePanel.ID =
"CitySystemUpdatePanel";
CitySystemPanel.Controls.Add(CitySystemUpdatePanel);
/* ---------------------------------------------------------------------------*/
// timer to trigger update
Timer CitySystemTimer = new Timer();
CitySystemTimer.ID =
"CityTimer";
CitySystemTimer.Interval = 30000;
CitySystemTimer.Enabled =
true;
CitySystemUpdatePanel.ContentTemplateContainer.Controls.Add(CitySystemTimer);

 
 
This page is generated completely using c# so i can not just split the web and the c#
Any Ideas would be great!
Jeff