I have some javascript that should log a user out after a certain period of inactive time.
I have an event handler in the code behind that handles the normal LoggingOut event of the LoginStatus object, but I can’t figure out how to call it from my javascript.
I know you can use __doPostBack to call an event handler that handles the Click event of a link or button, but it doesn’t seem to work for my LoginStatus object – I’m thinking it might be because it has no Click event (here’s the doc) – it’s not really a normal link/button.
The only other way I can think of to handle this is to create an actual logout button/link, write another event handler that does the same thing as my LoginStatus event handler, and call this new one using __doPostBack – but I don’t really like this idea.
Is there any way I can call the LoggingOut event handler from my javascript?
The page:
// html
<asp:LoginStatus ID="loginstatus" runat="server" />
...
// js
function expireSession() {
__doPostBack('loginstatus', ''); // doesn't seem to work
}
The code behind:
Protected Sub loginstatus_LoggingOut(ByVal sender...) Handles loginstatus.LoggingOut
Logout() // this is my own logout sub
End Sub
I’d suggest you take a different tact.
Create a “logout” page that simply clears the cookies/session/whatever and redirects the user to a regular login page. When the timer has elapsed do a javascript redirect to your logout page.