Obté o estableix el nombre de milisegons que es va a esperar abans d’iniciar un postback.Gets or sets the number of milliseconds to wait before initiating a postback.
public: property int Interval { int get(); void set(int value); };
public int Interval { get; set; }
member this.Interval : int with get, set
Public Property Interval As Integer
Valor de propietat
Int32
Nombre de milisegons que es va a esperar abans d’iniciar un postback.The number of milliseconds to wait before initiating a postback. Per omissió és 60.000 (60 segons) .The default value is 60,000 (60 seconds).
Excepcions
El valor especificat és menor o igual que cero.The specified value is less than or equal to zero.
Exemples
En l’exemple següent es mostra un UpdatePanel control que mostra un preu de les accions generat aleatòriament i l’hora a la qual s’ha generat el precio.The following example shows an UpdatePanel control that displays a randomly generated estoc price and the time that the estoc price was generated. Per defecte, el Timer control actualitza el contingut de l’UpdatePanel control cada 10 segundos.By default, the Timer control updates the content in the UpdatePanel control every 10 seconds. L’usuari pot decidir actualitzar el preu de les accions cada 10 segons, cada 60 segons, o no en absoluto.The user can decideix to update the estoc price every 10 seconds, every 60 seconds, or not at all. La Interval propietat s’estableix en l’elecció de l’usuario.The Interval property is setembre to the user ‘s choice.
<%@ Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><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"); } protected void RadioButton1_CheckedChanged(object sender, EventArgs e) { Timer1.Enabled = true; Timer1.Interval = 10000; } protected void RadioButton2_CheckedChanged(object sender, EventArgs e) { Timer1.Enabled = true; Timer1.Interval = 60000; } protected void RadioButton3_CheckedChanged(object sender, EventArgs e) { Timer1.Enabled = false; } </script></head><body> <form runat="server"> <asp:ScriptManager runat="server" /> <asp:Timer OnTick="Timer1_Tick" runat="server" Interval="10000" /> <asp:UpdatePanel runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" /> </Triggers> <ContentTemplate> Stock price is <asp:Label runat="server"></asp:Label><BR /> as of <asp:Label runat="server"></asp:Label> <br /> </ContentTemplate> </asp:UpdatePanel> <div> <br /> Update stock price every:<br /> <asp:RadioButton AutoPostBack="true" GroupName="TimerFrequency" runat="server" Text="10 seconds" OnCheckedChanged="RadioButton1_CheckedChanged" /><br /> <asp:RadioButton AutoPostBack="true" GroupName="TimerFrequency" runat="server" Text="60 seconds" OnCheckedChanged="RadioButton2_CheckedChanged" /><br /> <asp:RadioButton AutoPostBack="true" GroupName="TimerFrequency" runat="server" Text="Never" OnCheckedChanged="RadioButton3_CheckedChanged" /> <br /> Page loaded at <asp:Label runat="server"></asp:Label> </div> </form></body></html>
<%@ Page Language="VB" AutoEventWireup="true" %><!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>Timer Example Page</title> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) OriginalTime.Text = DateTime.Now.ToLongTimeString() End Sub Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) StockPrice.Text = GetStockPrice() TimeOfPrice.Text = DateTime.Now.ToLongTimeString() End Sub Private Function GetStockPrice() As String Dim randomStockPrice As Double = 50 + New Random().NextDouble() Return randomStockPrice.ToString("C") End Function Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Timer1.Interval = 10000 Timer1.Enabled = True End Sub Protected Sub RadioButton2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Timer1.Interval = 60000 Timer1.Enabled = True End Sub Protected Sub RadioButton3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Timer1.Enabled = False End Sub</script></head><body> <form runat="server"> <asp:ScriptManager runat="server" /> <asp:Timer OnTick="Timer1_Tick" runat="server" Interval="10000" /> <asp:UpdatePanel runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" /> </Triggers> <ContentTemplate> Stock price is <asp:Label runat="server"></asp:Label><BR /> as of <asp:Label runat="server"></asp:Label> </ContentTemplate> </asp:UpdatePanel> <div> <asp:RadioButton AutoPostBack="true" GroupName="TimerFrequency" runat="server" Text="10 seconds" OnCheckedChanged="RadioButton1_CheckedChanged" /><br /> <asp:RadioButton AutoPostBack="true" GroupName="TimerFrequency" runat="server" Text="60 seconds" OnCheckedChanged="RadioButton2_CheckedChanged" /><br /> <asp:RadioButton AutoPostBack="true" GroupName="TimerFrequency" runat="server" Text="Never" OnCheckedChanged="RadioButton3_CheckedChanged" /><br /> <br /> Page originally created at <asp:Label runat="server"></asp:Label> </div> </form></body></html>
Comentaris
Utilitzeu la Interval propietat per establir la freqüència amb què el Timer control inicia un postback al servidor.Use the Interval property to setembre how often the Timer control initiates a postback to the server. Es pot canviar la de la Interval propietat en el codi de l’servidor després d’un postback, com en un controlador d’esdeveniments per al Tick evento.You can change the value of the Interval property in server code after a postback, such as in an event handler for the Tick event. La precisió de quan el Timer control retorna dades a el servidor web depèn de la precisió de la funció ECMAScript (JavaScript) window.setTimeout
que s’executa en el explorador.The accuracy of when the Timer control posts back to the Web server depends on the accuracy of the ECMAScript (JavaScript) window.setTimeout
function that runs in the browser.
Nota
l’establiment de la Interval propietat en un valor petit pot generar un trànsit significatiu cap i des del servidor Web.Setting the Interval property to a small value can generate significant traffic to and from the Web server. Utilitzeu el Timer control per actualitzar el contingut només amb la freqüència que sigui necesaria.Use the Timer control to refresh the content only as often as necessary.
A l’canviar el valor de la Interval propietat, el codi de temps de ECMAScript que s’executa en el navegador es restablirà quan es representin les actualizaciones.When you change the value of the Interval property, the ECMAScript timing code running in the browser will be reset when the updates are rendered.