Hello People!
Hope, you solve my problem.
I program in VB.NET and have a WebForm that contain a client Javascript counter (min:sec) to zero. I use this code to show up a counter.
<script language="javascript">
var up,down;
var min1,sec1;
var cmin1,csec1,cmin2,csec2;
function Minutes(data) {
for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
return(data.substring(0,i)); }
function Seconds(data) {
for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;
return(data.substring(i+1,data.length)); }
function Display(min,sec) {
var disp;
if(min<=9) disp=" 0";
else disp=" ";
disp+=min+":";
if(sec<=9) disp+="0"+sec;
else disp+=sec;
return(disp); }
function Down() {
cmin2=1*Minutes(document.sw.beg2.value);
csec2=0+Seconds(document.sw.beg2.value);
DownRepeat(); }
function DownRepeat() {
csec2--;
if(csec2==-1) { csec2=59; cmin2--; }
document.sw.disp2.value=Display(cmin2,csec2);
if((cmin2==0)&&(csec2==0)) alert("Timer-CountDown Stopped");
else down=setTimeout("DownRepeat()",1000); }
// End -->
</script>
Function is called from here: <body onload="Down()".... >
And a value I get from the server session variable (Session("myLimit"))
It described in this client container.
<form name="sw">
<INPUT id=timeToCount style="Z-INDEX: 101; LEFT: 40px; VISIBILITY: hidden; POSITION: absolute; TOP: 408px"
readOnly type=text size=3 value='<%=Session("myLimit")%>' name=beg2>
<INPUT id="myCount" style="Z-INDEX: 103; LEFT: 32px; WIDTH: 61px; POSITION: absolute; TOP: 344px; HEIGHT: 22px" readOnly type="text" size="4" name="disp2">
</form>
The timer is functioning well. For example, if session ("myLimit") = 5, then on WebForm load it begin counting 4:59 to zero.
What I need:
- Add a counter pause/unpause button.
- Need this timer to survive postbacks (I have another button on the form and on press it fire postback and reset a counter)
- When counter reaches zero I have to do any server side command (for example, Label2.Text="Time is up" , where label2 is a server control)
Maybe I ask too much, but if you can help me with these 3 :sad: