Step : 2 Code
Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for TimerChecker
/// </summary>
public class TimerChecker
{
public TimerChecker()
{
//
// TODO: Add constructor logic here
//
}
public string stock_price()
{
double randomStockPrice = 50 + new Random().NextDouble();
return randomStockPrice.ToString("C") + " Stock Reporter ";
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!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>mm.Timer1, Triggers, UpdatePanel</title>
</head>
<body>
<form id="form1" runat="server">
<div> Example of AsyncPostBackTrigger </br>
<asp:Label ID="L1" runat="server" Text="Label"></asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server"
Interval="10000" />
<asp:UpdatePanel ID="UPl" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
<asp:Label id="L3" runat="server"></asp:Label><br />
<asp:Label id="L4" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<div>
<hr /><asp:Label ID="L2" runat="server"></asp:Label>
</div>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected static int n1;
protected void Page_Load(object sender, EventArgs e)
{
//if (!IsPostBack)
// {
L1.Text = "Page Load The time is now: <br />";
L1.Text += DateTime.Now.ToString();
L1.Text += "<br/> Loop Back " + (n1++);
}
protected void Timer1_Tick(object sender, EventArgs e)
{
TimerChecker tc = new TimerChecker();
L3.Text += "<br/> StockPrice\t <br/>" + tc.stock_price() + "\t" +
"   : @ : " + DateTime.Now.ToLongTimeString();
}
}