2009-07-31 6 views
1

Salut, je veux appeler une méthode basée sur une seule fois la duréeMéthode appels avec intervalle de temps (asp.net C#)

voici mon parcours

BindData protected void (object sender, EventArgs e) { // ma logique ici }

maintenant, je veux appeler cette méthode pour toutes les 5 minutes

utilisant C# et asp.net comment puis-je y parvenir?

merci

Répondre

1

vous disposez d'un contrôle de temporisation dans les contrôles ajax ASP.Net.
http://msdn.microsoft.com/fr-fr/library/system.web.ui.timer.aspx

Il fournit une postbak

de msdn exemple:

<%@ Page Language="C#" AutoEventWireup="true" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html > 
<head runat="server"> 
    <title>Timer Example Page</title> 
    <script runat="server"> 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      OriginalTime.Text = DateTime.Now.ToLongTimeString(); 
     } 

     protected void Timer1_Tick(object sender, EventArgs e) 
     { 
      StockPrice.Text = GetStockPrice(); 
      TimeOfPrice.Text = DateTime.Now.ToLongTimeString(); 
     } 

     private string GetStockPrice() 
     { 
      double randomStockPrice = 50 + new Random().NextDouble(); 
      return randomStockPrice.ToString("C"); 
     } 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
     <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000" /> 

     <asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional"> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="Timer1" /> 
     </Triggers> 
     <ContentTemplate> 
      Stock price is <asp:Label id="StockPrice" runat="server"></asp:Label><BR /> 
      as of <asp:Label id="TimeOfPrice" runat="server"></asp:Label> 
     </ContentTemplate> 
     </asp:UpdatePanel> 
     <div> 
     Page originally created at <asp:Label ID="OriginalTime" runat="server"></asp:Label> 
     </div> 
    </form> 
</body> 
</html> 

Hope this aide.

+0

oui exactement c'est ce que je cherche – Nagu

+0

ohhhhhh non dans cette méthode toute la page se rafraîchie. Je ne veux pas faire comme ça. Juste je veux appeler une méthode particulière seulement – Nagu

1
Timer myTimer = new Timer(); 
myTimer.Elapsed += new ElapsedEventHandler(binddata); 
myTimer.Interval = 5*60*100; 
myTimer.Start(); 
Questions connexes