Timer control's Tick event is not working on WSS Web Part<p><strong>Sample Code is :- <br/><br/>Code from .cs </strong>file<br/><br/><span style="font-size:x-small"><font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">protected</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#0000ff">void</span><span style="font-size:x-small"> Page_Load(</span><span style="font-size:x-small;color:#0000ff">object</span><span style="font-size:x-small"> sender, </span><span style="font-size:x-small;color:#008080">EventArgs</span><span style="font-size:x-small"> e) <p>{</p> <font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">if</span><span style="font-size:x-small"> (!Page.IsPostBack) <p>{</p> <font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">try</span></p> <span style="font-size:x-small"> <p>{</p> <font size=2> <p>StrConnection =</p> </font></span> <p><span style="font-size:x-small;color:#800000">&quot;data source=&quot;</span><span style="font-size:x-small"> + System.Configuration.</span><span style="font-size:x-small;color:#008080">ConfigurationManager</span><span style="font-size:x-small">.AppSettings[</span><span style="font-size:x-small;color:#800000">&quot;Server&quot;</span><span style="font-size:x-small">].ToString() + </span><span style="font-size:x-small;color:#800000">&quot;;initial catalog=&quot;</span><span style="font-size:x-small"> + System.Configuration.</span><span style="font-size:x-small;color:#008080">ConfigurationManager</span><span style="font-size:x-small">.AppSettings[</span><span style="font-size:x-small;color:#800000">&quot;Database&quot;</span><span style="font-size:x-small">].ToString() + </span><span style="font-size:x-small;color:#800000">&quot;;User ID=&quot;</span><span style="font-size:x-small"> + System.Configuration.</span><span style="font-size:x-small;color:#008080">ConfigurationManager</span><span style="font-size:x-small">.AppSettings[</span><span style="font-size:x-small;color:#800000">&quot;Username&quot;</span><span style="font-size:x-small">].ToString() + </span><span style="font-size:x-small;color:#800000">&quot;;Password=&quot;</span><span style="font-size:x-small"> + System.Configuration.</span><span style="font-size:x-small;color:#008080">ConfigurationManager</span><span style="font-size:x-small">.AppSettings[</span><span style="font-size:x-small;color:#800000">&quot;Password1&quot;</span><span style="font-size:x-small">].ToString() + </span><span style="font-size:x-small;color:#800000">&quot;;persist security info=True;packet size=4096&quot;</span><span style="font-size:x-small">; <p>getSelectData();</p> <font size=2> <p>Label1.Text =</p> </font></span></p> <p><span style="font-size:x-small;color:#008080">DateTime</span><span style="font-size:x-small">.Now.ToLongTimeString();<font size=2> <p>timer =</p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">new</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#008080">Timer</span><span style="font-size:x-small">(); <p>timer.Interval = 1000;</p> <font size=2> <p>timer.Tick +=</p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">new</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#008080">EventHandler</span><span style="font-size:x-small">(TimerHandler); <p>}</p> <font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">catch</span><span style="font-size:x-small"> (System.</span><span style="font-size:x-small;color:#008080">Exception</span><span style="font-size:x-small"> ErrMessage) <p>{</p> <p>Response.Write(ErrMessage.Message.ToString());</p> <p>}</p> <p>}</p> <p>}</p> <font size=2> <p> </p> </font></span></p> <p><br/><br/><br/>Code from Html<br/><br/><br/><br/><br/><br/><span style="font-size:x-small;color:#0000ff"><font size=2 color="#0000ff"> <p>&lt;</p> </font></span></p> <p><span style="font-size:x-small;color:#800000">asp</span><span style="font-size:x-small;color:#0000ff">:</span><span style="font-size:x-small;color:#800000">ScriptManager</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">ID</span><span style="font-size:x-small;color:#0000ff">=&quot;ScriptManager&quot;</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">runat</span><span style="font-size:x-small;color:#0000ff">=&quot;server&quot;/&gt;<font size=2 color="#0000ff"> <p>&lt;</p> </font></span></p> <p><span style="font-size:x-small;color:#800000">asp</span><span style="font-size:x-small;color:#0000ff">:</span><span style="font-size:x-small;color:#800000">UpdatePanel</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">ID</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#0000ff">=&quot;UpdatePanel1&quot;</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">runat</span><span style="font-size:x-small;color:#0000ff">=&quot;server&quot;</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">UpdateMode</span><span style="font-size:x-small;color:#0000ff">=&quot;Conditional&quot;&gt;</span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="font-size:x-small;color:#0000ff">&lt;</span><span style="font-size:x-small;color:#800000">ContentTemplate</span><span style="font-size:x-small;color:#0000ff">&gt;</span><span style="font-size:x-small"> <br/><br/><br/> <p><span style="font-size:x-small;color:#0000ff">&lt;/</span><span style="font-size:x-small;color:#800000">ContentTemplate</span><span style="font-size:x-small;color:#0000ff">&gt;</span><span style="font-size:x-small"> <br/>&lt;/<span style="color:#800000">asp</span><span style="font-size:x-small;color:#0000ff">:</span><span style="font-size:x-small;color:#800000">UpdatePanel</span><span style="font-size:x-small">&gt;</span></span></p> </span></p>© 2009 Microsoft Corporation. All rights reserved.Wed, 29 Apr 2009 13:31:09 Z0810f2eb-8d0b-4b44-ae6e-afb528fadd13http://social.msdn.microsoft.com/Forums/en/olsbapps/thread/0810f2eb-8d0b-4b44-ae6e-afb528fadd13#0810f2eb-8d0b-4b44-ae6e-afb528fadd13http://social.msdn.microsoft.com/Forums/en/olsbapps/thread/0810f2eb-8d0b-4b44-ae6e-afb528fadd13#0810f2eb-8d0b-4b44-ae6e-afb528fadd13Harsh Wordhan Guptahttp://social.msdn.microsoft.com/Profile/en-US/?user=Harsh%20Wordhan%20GuptaTimer control's Tick event is not working on WSS Web Part<p><strong>Sample Code is :- <br/><br/>Code from .cs </strong>file<br/><br/><span style="font-size:x-small"><font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">protected</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#0000ff">void</span><span style="font-size:x-small"> Page_Load(</span><span style="font-size:x-small;color:#0000ff">object</span><span style="font-size:x-small"> sender, </span><span style="font-size:x-small;color:#008080">EventArgs</span><span style="font-size:x-small"> e) <p>{</p> <font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">if</span><span style="font-size:x-small"> (!Page.IsPostBack) <p>{</p> <font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">try</span></p> <span style="font-size:x-small"> <p>{</p> <font size=2> <p>StrConnection =</p> </font></span> <p><span style="font-size:x-small;color:#800000">&quot;data source=&quot;</span><span style="font-size:x-small"> + System.Configuration.</span><span style="font-size:x-small;color:#008080">ConfigurationManager</span><span style="font-size:x-small">.AppSettings[</span><span style="font-size:x-small;color:#800000">&quot;Server&quot;</span><span style="font-size:x-small">].ToString() + </span><span style="font-size:x-small;color:#800000">&quot;;initial catalog=&quot;</span><span style="font-size:x-small"> + System.Configuration.</span><span style="font-size:x-small;color:#008080">ConfigurationManager</span><span style="font-size:x-small">.AppSettings[</span><span style="font-size:x-small;color:#800000">&quot;Database&quot;</span><span style="font-size:x-small">].ToString() + </span><span style="font-size:x-small;color:#800000">&quot;;User ID=&quot;</span><span style="font-size:x-small"> + System.Configuration.</span><span style="font-size:x-small;color:#008080">ConfigurationManager</span><span style="font-size:x-small">.AppSettings[</span><span style="font-size:x-small;color:#800000">&quot;Username&quot;</span><span style="font-size:x-small">].ToString() + </span><span style="font-size:x-small;color:#800000">&quot;;Password=&quot;</span><span style="font-size:x-small"> + System.Configuration.</span><span style="font-size:x-small;color:#008080">ConfigurationManager</span><span style="font-size:x-small">.AppSettings[</span><span style="font-size:x-small;color:#800000">&quot;Password1&quot;</span><span style="font-size:x-small">].ToString() + </span><span style="font-size:x-small;color:#800000">&quot;;persist security info=True;packet size=4096&quot;</span><span style="font-size:x-small">; <p>getSelectData();</p> <font size=2> <p>Label1.Text =</p> </font></span></p> <p><span style="font-size:x-small;color:#008080">DateTime</span><span style="font-size:x-small">.Now.ToLongTimeString();<font size=2> <p>timer =</p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">new</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#008080">Timer</span><span style="font-size:x-small">(); <p>timer.Interval = 1000;</p> <font size=2> <p>timer.Tick +=</p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">new</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#008080">EventHandler</span><span style="font-size:x-small">(TimerHandler); <p>}</p> <font size=2> <p> </p> </font></span></p> <p><span style="font-size:x-small;color:#0000ff">catch</span><span style="font-size:x-small"> (System.</span><span style="font-size:x-small;color:#008080">Exception</span><span style="font-size:x-small"> ErrMessage) <p>{</p> <p>Response.Write(ErrMessage.Message.ToString());</p> <p>}</p> <p>}</p> <p>}</p> <font size=2> <p> </p> </font></span></p> <p><br/><br/><br/>Code from Html<br/><br/><br/><br/><br/><br/><span style="font-size:x-small;color:#0000ff"><font size=2 color="#0000ff"> <p>&lt;</p> </font></span></p> <p><span style="font-size:x-small;color:#800000">asp</span><span style="font-size:x-small;color:#0000ff">:</span><span style="font-size:x-small;color:#800000">ScriptManager</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">ID</span><span style="font-size:x-small;color:#0000ff">=&quot;ScriptManager&quot;</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">runat</span><span style="font-size:x-small;color:#0000ff">=&quot;server&quot;/&gt;<font size=2 color="#0000ff"> <p>&lt;</p> </font></span></p> <p><span style="font-size:x-small;color:#800000">asp</span><span style="font-size:x-small;color:#0000ff">:</span><span style="font-size:x-small;color:#800000">UpdatePanel</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">ID</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#0000ff">=&quot;UpdatePanel1&quot;</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">runat</span><span style="font-size:x-small;color:#0000ff">=&quot;server&quot;</span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#ff0000">UpdateMode</span><span style="font-size:x-small;color:#0000ff">=&quot;Conditional&quot;&gt;</span></p> <span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="font-size:x-small;color:#0000ff">&lt;</span><span style="font-size:x-small;color:#800000">ContentTemplate</span><span style="font-size:x-small;color:#0000ff">&gt;</span><span style="font-size:x-small"> <br/><br/><br/> <p><span style="font-size:x-small;color:#0000ff">&lt;/</span><span style="font-size:x-small;color:#800000">ContentTemplate</span><span style="font-size:x-small;color:#0000ff">&gt;</span><span style="font-size:x-small"> <br/>&lt;/<span style="color:#800000">asp</span><span style="font-size:x-small;color:#0000ff">:</span><span style="font-size:x-small;color:#800000">UpdatePanel</span><span style="font-size:x-small">&gt;</span></span></p> </span></p>Mon, 13 Apr 2009 08:15:45 Z2009-04-13T08:15:45Zhttp://social.msdn.microsoft.com/Forums/en/olsbapps/thread/0810f2eb-8d0b-4b44-ae6e-afb528fadd13#4e37333d-687f-4769-9430-79134b649a6fhttp://social.msdn.microsoft.com/Forums/en/olsbapps/thread/0810f2eb-8d0b-4b44-ae6e-afb528fadd13#4e37333d-687f-4769-9430-79134b649a6fruijianhttp://social.msdn.microsoft.com/Profile/en-US/?user=ruijianTimer control's Tick event is not working on WSS Web Parti meet same ,i want to show system-time in moss webparts,and refurbisn 1s,but when <br/><strong>refreshName.ContentTemplateContainer.Controls.Add(tm);<br/>or<br/>AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();  all error<br/></strong><br/> <pre lang="x-c#">using System; using System.Text; using System.Runtime.InteropServices; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Serialization; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages; namespace HelloWebPart { [Guid(&quot;35bce816-acb9-4251-bf36-7981503535e9&quot;)] public class HelloWebPart : Microsoft.SharePoint.WebPartPages.WebPart { public HelloWebPart() { this.ExportMode = WebPartExportMode.All; } private Label displayName; private TextBox inputName; private Label showTime; string h = DateTime.Now.Hour.ToString();//获取系统时间小时 string m = DateTime.Now.Minute.ToString();//获取系统时间分钟 string s = DateTime.Now.Second.ToString();//获取系统时间秒 UpdatePanel refreshName = new UpdatePanel(); Timer tm = new Timer(); protected override void OnInit(EventArgs e) { base.OnInit(e); } protected override void CreateChildControls() { base.CreateChildControls(); //Fix for the UpdatePanel postback behaviour. EnsurePanelFix(); LinkButton sayHello = new LinkButton(); ScriptManager scriptHandler = new ScriptManager(); displayName = new Label(); inputName = new TextBox(); showTime = new Label(); this.showTime.ID = &quot;showtime&quot;; this.showTime.Text = &quot;T:&quot; + h + &quot;时&quot; + m + &quot;分&quot; + s + &quot;秒&quot;; //Set up control properties. this.displayName.ID = &quot;displayName&quot;; this.displayName.Text = &quot;Hello!&quot;; this.inputName.ID = &quot;inputName&quot;; sayHello.ID = &quot;sayHello&quot;; sayHello.Text = &quot;Say Hello&quot;; scriptHandler.ID = &quot;scriptHandler&quot;; refreshName.ID = &quot;refreshName&quot;; //refreshName.UpdateMode = UpdatePanelUpdateMode.Conditional; refreshName.UpdateMode = UpdatePanelUpdateMode.Always; refreshName.ChildrenAsTriggers = true; //Add the EventHandler to the Button. sayHello.Click += new EventHandler(ClickHandler); <strong> tm.Enabled = true; tm.ID = &quot;tm&quot;; tm.Interval = 1000000; tm.Tick += new EventHandler&lt;EventArgs&gt;(Tm_Tick); //refreshName.ContentTemplateContainer.Controls.Add(tm); AsyncPostBackTrigger trigger = new AsyncPostBackTrigger(); trigger.ControlID = &quot;tm&quot;; refreshName.Triggers.Add(trigger);</strong> //Add the user interface (UI) controls to the UpdatePanel. refreshName.ContentTemplateContainer.Controls.Add(this.inputName); refreshName.ContentTemplateContainer.Controls.Add(sayHello); refreshName.ContentTemplateContainer.Controls.Add(this.displayName); //refreshName.ContentTemplateContainer.Controls.Add(tm); refreshName.ContentTemplateContainer.Controls.Add(this.showTime); //The ScriptManager control must be added first. this.Controls.Add(scriptHandler); this.Controls.Add(refreshName); //this.Controls.Add(tm); } private void ClickHandler(object sender, EventArgs args) { this.displayName.Text = &quot;Hello, &quot; + this.inputName.Text.ToString() + &quot;.&quot;; } protected void Tm_Tick(object sender, EventArgs e) { this.showTime.Text = DateTime.Now.ToString(); } protected override void RenderWebPart(HtmlTextWriter output) { RenderChildren(output); } //修改脚本以确保正确的 doPostBack() 行为 private void EnsurePanelFix() { if (this.Page.Form != null) { String fixupScript = @&quot; _spBodyOnLoadFunctionNames.push(&quot;&quot;_initFormActionAjax&quot;&quot;); function _initFormActionAjax() { if (_spEscapedFormAction == document.forms[0].action) { document.forms[0]._initialAction = document.forms[0].action; } } var RestoreToOriginalFormActionCore = RestoreToOriginalFormAction; RestoreToOriginalFormAction = function() { if (_spOriginalFormAction != null) { RestoreToOriginalFormActionCore(); document.forms[0]._initialAction = document.forms[0].action; } }&quot;; ScriptManager.RegisterStartupScript(this, typeof(HelloWebPart), &quot;UpdatePanelFixup&quot;, fixupScript, true); } } } }</pre>Wed, 29 Apr 2009 13:31:09 Z2009-04-29T13:31:09Z