Step 1) Create Silverlight Project using Visual Studio 2010,(see article)
Step 2) Add new item->select Webpart name its "TimerWp"
Step 3) open TimerWp.cs
Replace with following code
FileName:TimerWp.cs
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace SharePointProject1.TimerWp
{
[ToolboxItemAttribute(false)]
public class TimerWp : WebPart
{
Label lblTime = new Label();
UpdatePanel updatePanel = new UpdatePanel();
Timer t = new Timer();
protected override void CreateChildControls()
{
lblTime.Text = "Time will be updated by Timer";
t.Interval = 1000;//1000 milli seconds
t.Tick += new EventHandler<EventArgs>(t_Tick);
//Add controls to WebPart zone container.
updatePanel.ContentTemplateContainer.Controls.Add(lblTime);
updatePanel.ContentTemplateContainer.Controls.Add(t);
this.Controls.Add(updatePanel);
}
void t_Tick(object sender, EventArgs e)
{
lblTime.Text = System.DateTime.Now.ToLongTimeString();
}
}
}
Step 3) Deploy the Solution
Step 4) Add Ajax Timer Webpart to a Site.,
OUTPUT
Step 2) Add new item->select Webpart name its "TimerWp"
Step 3) open TimerWp.cs
Replace with following code
FileName:TimerWp.cs
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace SharePointProject1.TimerWp
{
[ToolboxItemAttribute(false)]
public class TimerWp : WebPart
{
Label lblTime = new Label();
UpdatePanel updatePanel = new UpdatePanel();
Timer t = new Timer();
protected override void CreateChildControls()
{
lblTime.Text = "Time will be updated by Timer";
t.Interval = 1000;//1000 milli seconds
t.Tick += new EventHandler<EventArgs>(t_Tick);
//Add controls to WebPart zone container.
updatePanel.ContentTemplateContainer.Controls.Add(lblTime);
updatePanel.ContentTemplateContainer.Controls.Add(t);
this.Controls.Add(updatePanel);
}
void t_Tick(object sender, EventArgs e)
{
lblTime.Text = System.DateTime.Now.ToLongTimeString();
}
}
}
Step 3) Deploy the Solution
Step 4) Add Ajax Timer Webpart to a Site.,
OUTPUT
No comments:
Post a Comment