Saturday, March 24, 2012

ajax timer problem

Hi..
Iam using Ajax Enabled website in my Project iam using two Ajax Timer controls for displaying
two images in different time one for 5 seconds another for 2 seconds but it is displaying only one image

have you used two update panels for two timer controls?
Try updating panel, once one image is displayed. Then enable another timer.

i.e

timer1.enabled=true;
timer2.enabled=false;

timer1_tick() {
//display image

timer1.enabled=false;
timer2.enabled=true;
updatepanel.update() //if updatemode is set to conditional
}

timer2_tick() {
//display image

timer2.enabled=false;
updatepanel.update() //if updatemode is set to conditional

}


Hi,

I used two update panels for two timer controls then also its not working

protectedvoid HomeImages(object sender,EventArgs e)

{

if (n > 13)

n = 1;

if (n != 4)

{

Image1.ImageUrl =String.Concat("Dimages/image", n.ToString(),".jpg");

}

Image1.ImageUrl ="Dimages/images" + n.ToString() +".jpg";

n++;

homeImages.Enabled =false;Timer1.Enabled =true;

UpdatePanel1.Update();

}

protectedvoid Timer1_Tick3(object sender,EventArgs e)

{

if (k > 6)

k = 1;

Image3.ImageUrl =String.Concat("ClientsImages/clientimage", k.ToString(),".jpg");

// Image1.ImageUrl = "Dimages/images" + n.ToString() + ".jpg";

k++;

Timer1.Enabled =false;

UpdatePanel2.Update();

}


Hi Pathipati,

I have made a sample for your situation. Please wholly copy my source code and have a test.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">public static bool timer1State = false; public static bool timer2State = false; protected void Timer2_Tick(object sender, EventArgs e) { if (timer2State) { Image2.ImageUrl = "~/pic/expand.jpg"; } else { Image2.ImageUrl = "~/pic/collapse.jpg"; } timer2State = !timer2State; UpdatePanel2.Update(); } protected void Timer1_Tick(object sender, EventArgs e) { if (timer1State) { Image1.ImageUrl = "~/pic/expand.jpg"; } else { Image1.ImageUrl = "~/pic/collapse.jpg"; } timer1State = !timer1State; UpdatePanel1.Update(); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> UpdatePanel1:<%=DateTime.Now.ToString()%> <asp:Image ID="Image1" runat="server" ImageUrl="~/pic/expand.jpg" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"/> </Triggers> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> UpdatePanel2:<%=DateTime.Now.ToString()%> <asp:Image ID="Image2" runat="server" ImageUrl="~/pic/expand.jpg"/> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" /> </Triggers> </asp:UpdatePanel> <asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick"> </asp:Timer><asp:Timer ID="Timer2" runat="server" Interval="2000" ontick="Timer2_Tick"> </asp:Timer> </form></body></html>

Best regards,
Jonathan

No comments:

Post a Comment