Ciao a tutti,
ho inserito un asp timer all'interno della mia pagina web,
solo che mi sono accorto che se apro il sito solo in una pagina il timer funziona correttamente..
Se invece provo ad aprire un'altra pagine il timer si blocca.
di seguito la mia pagina:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="Pannello" runat="server">
<ContentTemplate>
<strong><asp:Label ID="lblTitolo" runat="server" Text="" /></strong>
<hr align="left" color="#dddddd" />
<br />
<asp:Label ID="lblTesto" runat="server" Text="" />
<hr color="#C41E3A">
<div style="width:100%; margin-bottom:30px;">
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
questo è il codice vb.net che ho scritto:
Imports System.Data
Imports System.Data.SqlClient
Partial Class News_newsciclo
Inherits System.Web.UI.Page
Dim con As SqlClient.SqlConnection
Shared ArrayTitolo As Array
Shared ArrayTesto As Array
Shared NumeroRighe As Integer
Shared n As Integer = 0
Dim ripetuto As Integer = 0
Private Function caricaNews() As Boolean
Dim strSql As String = "select Titolo, Testo from News"
Me.StartConnection()
Dim cmd As New SqlClient.SqlCommand(strSql, con)
Dim myreader As SqlDataReader = cmd.ExecuteReader()
Dim i As Integer = 0
While myreader.Read()
ArrayTitolo(i) = myreader(0).ToString
ArrayTesto(i) = myreader(1).ToString
i = i + 1
End While
Me.CloseConnection()
Return True
End Function
Private Function RecuperaNumeroRighe() As Integer
Me.StartConnection()
Dim NumRighe As Integer
Dim strIns As String
strIns = "SELECT COUNT(*) FROM News"
Dim cmd As New SqlClient.SqlCommand(strIns, con)
' If cmd.ExecuteScalar = Nothing Then
If IsDBNull(cmd.ExecuteScalar) Then
NumRighe = 0
Else
NumRighe = CInt(cmd.ExecuteScalar)
cmd.ExecuteNonQuery()
cmd.Dispose()
End If
Me.CloseConnection()
Return NumRighe
End Function
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Else
NumeroRighe = RecuperaNumeroRighe()
ArrayTitolo = inizializzaArray(NumeroRighe)
ArrayTesto = inizializzaArray(NumeroRighe)
caricaNews()
lblTesto.Text = ArrayTesto(0)
lblTitolo.Text = ArrayTitolo(0)
End If
End Sub
Protected Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
' simuliamo la lettura del web service
If ripetuto = 0 Then
lblTesto.Text = ArrayTesto(n)
lblTitolo.Text = ArrayTitolo(n)
If n = (NumeroRighe - 1) Then
n = 0
Else
n = n + 1
End If
ripetuto = 1
Else
ripetuto = 0
End If
End Sub
Public Function inizializzaArray(ByRef numeroDomande As Integer) As Array
Dim newArray(numeroDomande - 1) As String
For i = 0 To (numeroDomande - 1)
newArray(i) = ""
Next
Return newArray
End Function
End Class
Qualcuno di voi saprebbe dirmi dove sbaglio?
Grazie mille per il supporto.
Marco