Click here to Skip to main content
15,890,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Timers;

namespace WebApplication1
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                addimages2();
            }
        }



        private void addimages2()
        {
            Random rand = new Random();
            int i = rand.Next(1, 4);
            Image1.ImageUrl = "~/pics/" + i.ToString() + ".jpg";
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            addimages2();
        }






    }
}





XML
<asp:UpdatePanel ID="UpdatePanel1" runat="server">

                <ContentTemplate>
                 <asp:Image ID="Image1" runat="server" Width="200px" Height="121px" />
                    <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
                    </asp:Timer>
                </ContentTemplate>

                </asp:UpdatePanel>
Posted
Updated 14-Nov-14 6:55am
v4
Comments
BillWoodruff 13-Nov-14 1:35am    
Have you tried refreshing the Image after you load the new picture in ?
Nitin Guralwar 13-Nov-14 2:31am    
no ,
sorry how to do it?
ZurdoDev 13-Nov-14 7:56am    
What's the exact error?
Nitin Guralwar 13-Nov-14 10:30am    
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'ASP.events_aspx' does not contain a definition for 'Timer1_Tick' and no extension method 'Timer1_Tick' accepting a first argument of type 'ASP.events_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 12:
Line 13: <contenttemplate>
Line 14: <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick" >
Line 15:
Line 16:
ZurdoDev 13-Nov-14 10:34am    
I've had issues like this in the past. You may need to change protected to private on your Timer1_Tick event.

Or, you can wire it up in C# Page_Load

Timer1.Tick += new ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900