Sunday, March 11, 2012

Ajax 101 question

Yeah set a flag to pause the timer if in edit mode. Dont know how you have implemented your code so cant advise more than that.


It's really basic

im writing in c#

Timer set to 10000

timer function

protected void Timer1_Tick(object sender, EventArgs e)
{//need to stop if grid in edit

GridView1.DataBind();
}

GridView1 is the GW in question

think i can do somthing like

protected void Timer1_Tick(object sender, EventArgs e)
{//need to stop if grid in edit
if(gridviewineditmode)

return
else

GridView1.DataBind();
}

Follow up question is the timer event only on the client if no call back to the server?


Hi Harperator,

Based on my experience , I think your can stop the Timer on theserver side by using timer.Enabled = false; .

Also you can implement it on the client side. Here is the sample.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="timer.aspx.cs" Inherits="timer" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager runat="server" ID="ScriptManager1" /> <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional"> <ContentTemplate><%=DateTime.Now.ToString()%> <asp:Timer ID="Timer1" runat="server" Interval="1000"> </asp:Timer> </ContentTemplate> </asp:UpdatePanel> <input id="Button1" type="button" value="Disable" onclick="changeState(false)" /> <input id="Button2" type="button" value="Enable" onclick="changeState(true)" /> <script language="javascript" type="text/javascript"> function changeState(value){ if(!value) $find("<%=Timer1.ClientID%>")._stopTimer(); else $find("<%=Timer1.ClientID%>")._startTimer(); } </script> </form></body></html>
I hope this help.
Best regards,
Jonathan


the simplest way to handle this is as under (not tested but should work), but just ran a non grid test...work fine there...

create a static bool on the page

public static bool flag = false;

in your timer if flag is false keep it running so

if (flag==false)

{

//Rest of the code..

Timer.run();

}

else timer.stop()///whatever your timer pause or stop is..I dont know..without your actual code

Now in grid edit function set the flag to true..

protected gridEditfunction(object....)

{

flag= true;

}

Now the timer will stop as soon as flag is set to true...

No comments:

Post a Comment