Default.aspx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <%@ Page Language="C#" AutoEventWireup="true" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title>Timer Example Page</title>
  6. <script runat="server">
  7. protected void Page_Load(object sender, EventArgs e)
  8. {
  9. OriginalTime.Text = DateTime.Now.ToLongTimeString();
  10. }
  11. protected void Timer1_Tick(object sender, EventArgs e)
  12. {
  13. StockPrice.Text = GetStockPrice();
  14. TimeOfPrice.Text = DateTime.Now.ToLongTimeString();
  15. }
  16. private string GetStockPrice()
  17. {
  18. double randomStockPrice = 50 + new Random().NextDouble();
  19. return randomStockPrice.ToString("C");
  20. }
  21. </script>
  22. </head>
  23. <body>
  24. <form id="form1" runat="server">
  25. <asp:ScriptManager ID="ScriptManager1" runat="server" />
  26. <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000" />
  27. <asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional">
  28. <Triggers>
  29. <asp:AsyncPostBackTrigger ControlID="Timer1" />
  30. </Triggers>
  31. <ContentTemplate>
  32. Stock price is <asp:Label id="StockPrice" runat="server"></asp:Label><BR />
  33. as of <asp:Label id="TimeOfPrice" runat="server"></asp:Label>
  34. </ContentTemplate>
  35. </asp:UpdatePanel>
  36. <div>
  37. Page originally created at <asp:Label ID="OriginalTime" runat="server"></asp:Label>
  38. </div>
  39. </form>
  40. </body>
  41. </html>