having error in timer tick event
Bash
Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="L_PaperSet.aspx.cs" Inherits="Lib_Web.WebForm2" %> asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> style type="text/css"> .style7 { width: 100%; } .style8 { width: 228px; } style> /asp:Content> asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> table class="style7"> tr> td class="style8"> /td> td> asp:ScriptManager ID="ScriptManager1" runat="server"> /asp:ScriptManager> asp:UpdatePanel ID="UpdatePanel1" runat="server"> ContentTemplate> asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick"> /asp:Timer> asp:Image ID="Image1" runat="server" /> /ContentTemplate> /asp:UpdatePanel> /td> /tr> tr> td class="style8"> /td> td> /td> /tr> /table> /asp:Content>C#
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Lib_Web { public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { NewMethod(); } } protected void Timer1_Tick(object sender, EventArgs e) { NewMethod(); } private void NewMethod() { Random rand = new Random(); int i = rand.Next(1, 4); Image1.ImageUrl = "~/L_pics/" + i.ToString() + ".jpg"; } } }VB.NET
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.l_paperset_aspx' does not contain a definition for 'Timer1_Tick' and no extension method 'Timer1_Tick' accepting a first argument of type 'ASP.l_paperset_aspx' could be found (are you missing a using directive or an assembly reference?) Source Error: Line 23:
Line 24:
Line 25:
Line 26:
Line 27:
Vikram AgrawalRank #4,713 · 329 reputationPosted Nov 16, 2014, 8:04 PM EST
Hi Nitin,
You can see in your code that you have defined CodeBehind="L_PaperSet.aspx.cs" but you have written all codes in Webform2.aspx.cs that's why this error is coming.
You can just change CodeBehind="Webform2.aspx.cs"
then Timer_Tick event will work
and one more thing you didn't set Interval property of timer control if you don't set it then it will take default value which is 60,000 (60seconds).
if you not set this Interval property then Timer_Tick event will occur after 60 seconds
Thank You,
Mark This is Correct Answer if it is Helpful to you
nitin4 reputationPosted Nov 17, 2014, 3:25 AM EST