Bonjour à tous,

J'ai peu d'épérience en Vb.NET et je souhaite créer un diaporama dans une page ASPX. Je n'arrive pas à déclarer la méthode "Elapsed" du contrôle Timer.

Ce contrôle est-il utilisable dans une page ASPX ? Sinon, comment peut-on programmer une action qui se déclanche en boucle chaque fois qu'un temps X s'est évoulé ?

Je vous remercie.
Paul Van Walleghem

P.S: Pour information, voici le code que j'ai écris. Il est dans un fichier .aspx.vb.
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
Imports System
Imports System.Data
Imports System.IO
Imports System.Timers
 
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim nbrPhotos As Integer = 1
    Dim oCollPhotos As New Collection
    Dim oTimer As New Timer
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For Each cPhotosDir As String In Directory.GetFiles(Directory.GetCurrentDirectory)
            oCollPhotos.Add(Path.GetFileName(cPhotosDir), Format(nbrPhotos))
            nbrPhotos = nbrPhotos + 1
        Next
        AddHandler oTimer.Elapsed, oTimer_Elapsed()
    End Sub
    'Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Protected Sub oTimer_Elapsed()
        Dim cRep As String = ""
        Dim nItem As Integer = Aleatoire(oCollPhotos.Count)
        If oCollPhotos(nItem) <> "Thumbs.db" Then
            TextBox1.Text = "nItem:   " & Str(nItem) & "   et Item:  " & oCollPhotos(nItem)
            cRep = "~/Metamorphose/" & oCollPhotos(nItem)
            Image1.ImageUrl = cRep
        Else
            TextBox1.Text = "Thumbs.db"
        End If
 
    End Sub
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        oTimer.Start()
    End Sub
    Function Aleatoire(ByVal nMax As Integer)
        ' Initialize the random-number generator.
        Randomize()
        Dim nAlea As Integer = CInt(Int((nMax * Rnd()) + 1))
        Return nAlea
    End Function
End Class