2 Replies - 1880 Views - Last Post: 20 July 2012 - 09:03 PM Rate Topic: -----

#1 JoeSan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-July 12

asp.net ajax timer control fires twice then stops

Posted 17 July 2012 - 04:36 PM

Basically I'm simply trying to implement a timer control that will swap banners for me and then update in an update panel.. however it only fires once, and appears to be firing twice(I put a label on a form an attempted to increment by one each time it would updated, and it jumped to 2 then stopped). Any help would be appreciated, as I am thoroughly confused as to why this is happening
        <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>




and heres the code behind.
Partial Class Assignment5MasterPage
    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
        If IsPostBack Then
            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 If


    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: asp.net ajax timer control fires twice then stops

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: asp.net ajax timer control fires twice then stops

Posted 18 July 2012 - 12:40 AM

*Moved to ASP.net forum for better replies.*
Please post your next threads in appropriate forums
Was This Post Helpful? 0
  • +
  • -

#3 mrburnttoast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 28-December 11

Re: asp.net ajax timer control fires twice then stops

Posted 20 July 2012 - 09:03 PM

I just tried your code and it works if you change
Dim n As Integer = New Random().Next(1, 2)

to
Dim n As Integer = New Random().Next(1, 3)

. Also you may need to add the eventname such as:
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"/>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1