Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 call code-behind from javascript timer

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2007-07-24 : 17:29:06
I've had a lot of help with some session timeout issues from other postings. Thank you to all who have responded and given input. Everything is helpful!

What I'd like to do is have a time via javascript that calls an Update/Save routine at 19 minutes of inactivity.

We've left our Session timeout value to 20 minutes, and it's been asked if we can simply save/update data automatically, so if the user session times out in another minute, they haven't lost any data entry.

I know how to show a client side pop-up warning at 15 minutes, but haven't figured out how to make the client side javascript call something in code behind.

Thanks!

karuna
Aged Yak Warrior

582 Posts

Posted - 2007-07-24 : 17:31:05
How about using XMLHTTP?
Go to Top of Page

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2007-07-25 : 10:47:28
I'm trying the following and get a javascript error about the myHiddenButtonID is not defined:

*****

HTML

******

</head>

<!-- Start timeout code -->

<body onmousedown = "window_activity()" onkeypress="window_activity()">

<script type="text/javascript">

var timerPROMPT = 0;

var timerCLOSE = 0;

function EndApp(){

//RateDeck.style.display = "none"

//spDeck.style.display = "none"

}

function StopTiming(){

if(timerPROMPT > 0)

window.clearTimeout(timerPROMPT)

//call button

var myHiddenButton = document.getElementById(myHiddenButtonID);

myHiddenButton.Click()

//end button call

if (confirm('Due to inactivity, your session is about to time out.')== 1)

{

if(timerCLOSE > 0)

window.clearTimeout(timerCLOSE)

timerPROMPT = window.setTimeout("StopTiming()",5000);

timerCLOSE = window.setTimeout("EndApp()",8000);

}

else

{

EndApp();

}

}

function window_activity() {

if(timerPROMPT > 0)

window.clearTimeout(timerPROMPT)

if(timerCLOSE > 0)

window.clearTimeout(timerCLOSE)

timerPROMPT = window.setTimeout("StopTiming()",5000);

timerCLOSE = window.setTimeout("EndApp()",6000);

}

</script>

<!-- End timout code -->

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="myHiddenButtonID" runat="server" Font-Size="XX-Small" OnClick="myHiddenButtonID_Click"

Text="Hide" /><br />

<br />

<br />


<asp:Image ID="Image1" runat="server" ImageUrl="~/images/top.jpg" />

</div>

</form>

</body>

</html>



*****

Code behind

****

protected void myHiddenButtonID_Click(object sender, EventArgs e)

{

Response.Write("Hidden button click event!");

}
Go to Top of Page

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2007-07-25 : 11:01:13
So, just changed the javascript to:

//call button

var myHiddenButton = document.getElementById("myHiddenButtonID");

myHiddenButton.OnClick();

//end button call


..and tried:

myHiddenButton.Click();


..and now I get the object doesn't support this proptery or method in a javascript error
Go to Top of Page
   

- Advertisement -