基本上我只是想实现一个计时器控件,它将为我交换横幅,然后在更新面板中进行更新。然而,计时器只影响我的页面一次,并且似乎触发了两次(我在表单上放置了一个标签,并尝试在每次更新时增加一,然后它跳到 2 然后停止)。
<asp:ContentPlaceHolder ID="cphHead" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="6000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/banner_2.jpg" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</asp:ContentPlaceHolder>
还有我的代码
Partial Class ASPTravel
Inherits System.Web.UI.MasterPage
Private intnum As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub LoginStatus1_LoggingOut(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles LoginStatus1.LoggingOut
Session.Abandon()
End Sub
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
intnum = intnum + 1
Label1.Text = CStr(intnum)
' If intnum = 0 Then
' Image1.ImageUrl = "~/images/banner_1.jpg"
' intnum = 1
' Else
' Image1.ImageUrl = "~/images/banner_2.jpg"
'End If
Dim n As Integer = New Random().Next(1, 2)
Image1.ImageUrl = "~/images/banner_" + n.ToString() + ".jpg"
End Sub
End Class