Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > .NET App with JavaScript : autologoff
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 17th September 20:40
jon delano
External User
 
Posts: 1
Default .NET App with JavaScript : autologoff



Hello

Thanks for checking my thread, I'm sure this is something that will be
fairly easy to answer.
Though will be a little long to explain.

Please stick with me :-)

I have a container form in ASP.NET (visual studio 2003 using vb.net).
on this form I have a label, where I load other pages.

When a user clicks a button for a particular "section" of data then I run
code like this :
Label1.Text = "<IFRAME SRC=""" & "PatientLabs.aspx" & """ width=" &
Session("ScreenWidth") & " height=" & Session("ScreenHeight") & "
FRAMEBORDER=0></IFRAME>"

This works really well, except for this auto logoff I have on the form. I
have some javascript I use to display the time left until the session is
automatically ended due to inactivity. I use this to handle the auto logoff
on the "parent" form

================================================== ========

<!--
var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

var start=new Date();
document.getElementById('txtTimerStart').innerText = start;
start=Date.parse(start)/1000;
var counts=90; // number of seconds til automatic logoff
function CountDown(){
var now=new Date();
now=Date.parse(now)/1000;
var x=parseInt(counts-(now-start),10);
var y=parseInt(x/60,10);
var z=parseInt(x%60,10);
//if(document.Form1){document.Form1.txtTimeout.value = 'AutoLogoff: ' + y
+ ' mins ' + z + ' secs';}
// Netscape 4
if(ns4){
document.layers['lblTimeout'].innerHTML = 'AutoLogoff in ' + y + ':' + z;
}
// Explorer 4
else if(ie4){
document.all['lblTimeout'].innerHTML = 'AutoLogoff in ' + y + ':' + z;
}
// W3C - Explorer 5+ and Netscape 6+
else if(ie5 || ns6){
document.getElementById('lblTimeout').innerHTML = 'AutoLogoff in ' + y +
':' + z;
}
if(x>0){timerID=setTimeout("CountDown()", 500)}
else{location.href='login.aspx'}
}

window.setTimeout('CountDown()',100);

================================================== ==========

Now, the IFRAME object doesn't have mousemove events, so when the mouse goes
in there.. the counter keeps counting down. This is a problem. Obviously.

So I tried to put a timer on the body of the "child" form I loaded into the
IFRAME, there I used the start value I put in the txtStartTimer, this is
updated each time the mouse moves on the parent, on the parent as the
starting point for the child. The child-timer gets out of sync with the
parent timer (they both update the same label on the parent form). So you
end up seeing two times in the label ... it'll say 1:15 and then 1:29 and
then 1:14 and then 1:28.

This is the javascript running on the child form:

var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

var Childstart=new Date();
// start=Date.parse(start)/1000;
Childstart=Date.parse(window.parent.document.all.i tem('txtTimerStart').value)/1000;
//Childstart=parent.start;
var counts=90; // number of seconds til automatic logoff
//var counts=15;
function CountDown(){
if (window.parent.document.all.item('txtFocus').value ='C') {
var now=new Date();
now=Date.parse(now)/1000;
var x=parseInt(counts-(now-Childstart),10);
var y=parseInt(x/60,10);
var z=parseInt(x%60,10);
//if(document.Form1){document.Form1.txtTimeout.value = 'AutoLogoff: ' + y
+ ' mins ' + z + ' secs';}
// Netscape 4
if(ns4){
parent.document.layers['lblTimeout'].innerHTML = 'AutoLogoff in ' + y +
':' + z;
}
// Explorer 4
else if(ie4){
parent.document.all['lblTimeout'].innerHTML = 'AutoLogoff in ' + y + ':'
+ z;
}
// W3C - Explorer 5+ and Netscape 6+
else if(ie5 || ns6){
parent.document.getElementById('lblTimeout').inner HTML = 'AutoLogoff in '
+ y + ':' + z;
}
if(x>0){timerID=setTimeout("CountDown()", 500)}
else{parent.location.href='login.aspx'}
}
}

window.setTimeout('CountDown()',100);

My question is two fold, can I use just the timer on the parent form only ?
If so, how ?

If not, how can I make sure the timer on the parent and child stay in sync
with each other so I don't have the battling timeouts ?

Thank you for sticking with this long post and for any assistance.

Jon
  Reply With Quote


 


2 17th September 20:40
jon delano
External User
 
Posts: 1
Default .NET App with JavaScript : autologoff



I changed my child timer to use the parent timer's variables ... then they
had no chioce but to stay insync.
  Reply With Quote
Reply


Thread Tools
Display Modes




666