Thanks Daniil, I used the code from the post you recommended. (Thanks to Equiman)
I made some small changes for having a winpopup requesting your credentials instead of redirecting to a login.aspx webform each time you have a timeout.
Also in the original code, in my case, I needed to use Ext.getCmp('frmTimeOut') for getting the popup window, and use window.hide and window.show instead window.SetVisible.
// URL Redirection
var timeOutSession = function () {
top.location.replace(GetNewPath('/KA.aspx'));
};
// Add this into Master Page (TabPanelContain):
// <DocumentReady Handler="masterTimeOut();stopCount();" />
var masterTimeOut = function () {
//Convert minutes value indicated in TimeOut del Web.Config to seconds
var min = 0;
var sec = 0;
var timer = null;
var vis = false;
var server = new Date().getTime() / 1000;
doTimer = function () {
var wnd = Ext.getCmp('frmTimeOut');
// At least 1 min, show the countdown window
if ((min - sec) < 60) {
updateTime();
if (wnd.hidden) {
vis = true;
wnd.show();
}
}
else {
if (!wnd.hidden) {
vis = false;
wnd.hide();
}
}
// Check the countdown counter
if ((min - sec) > 0) {
sec++;
// Repeat the process each minute
timer = setTimeout('doTimer()', 1000);
}
else {
// When countdown is finish, redirect to Login page
//timeOutSession();
var wnd = Ext.getCmp('frmTimeOut'); vis = false; wnd.hide();
clearTimeout(timer);
wnd = Ext.getCmp('wndL'); wnd.show();
}
};
stopCount = function () {
if (vis === true) {
//2 seconds Idle (no detect events, because showing alert window is detected as mousemove)
if ((min - sec) < 58) {
vis = false;
}
}
else {
// Convert minutes to second
min = (document.getElementById('txtMinTimeOut').value * 60);
sec = 0;
clearTimeout(timer);
// Get actual time
keepaliveServer((new Date().getTime() / 1000));
doTimer();
}
};
keepaliveServer = function (time) {
// Validating not saturation of the server with sending Keep Alive request
if ((time - server) > (min - 10)) {
var pageToCall = GetNewPath('/KA.aspx');
var requestParms = new Sys.Net.WebRequest();
requestParms.set_url(pageToCall);
requestParms.set_httpVerb("POST");
var message = "I'm keeping you alive!";
requestParms.set_body(message);
requestParms.get_headers()["Content-Length"] = message.length;
requestParms.add_completed(doNothing);
requestParms.invoke();
// Set new actual time
server = time;
}
};
doNothing = function (executor, eventArgs) { };
updateTime = function () {
var message = 'Inactividad detectada. Tu sesi?n caducar? en';
var time = (min - sec);
var unity = 'segundos.';
Ext.getCmp('lblText').setText(message + ' ' + time + ' ' + unity);
};
// Start counter on Load
document.onload = function () {
stopCount();
//return false;
};
// Star counter when mouse move
document.onmousemove = function () {
stopCount();
//return false;
};
// Star counter when key is pressed
document.onkeypress = function () {
stopCount();
//return false;
};
// Read and event when is send from an iFrame
function displayMessage(e) {
if ((e.origin.split(":", 2)[0] + ":" + e.origin.split(":", 2)[1]) === (GetNewPath("/").split(":", 2)[0] + ":" + GetNewPath("/").split(":", 2)[1])) {
// If the iFrame send any of this events start counter
switch (e.data) {
case "onload":
case "onmousemove":
case "onkeypress":
case "simulated":
stopCount();
}
}
};
if (window.addEventListener) {
// For standards-compliant web browsers
window.addEventListener("message", displayMessage, false);
}
else {
window.attachEvent("onmessage", displayMessage);
};
};
// Add this into any iFrame Page:
// <DocumentReady Handler="detailTimeOut();" />
var detailTimeOut = function () {
// Start counter on Load
document.onload = function () {
top.postMessage("onload", GetNewPath("/"));
return false;
};
// Star counter when mouse move
document.onmousemove = function () {
top.postMessage("onmousemove", GetNewPath("/"));
//return false;
};
// Star counter when key is pressed
document.onkeypress = function () {
top.postMessage("onkeypress", GetNewPath("/"));
//return false;
};
// Simulated Event
simulatedEvent = function () {
top.postMessage("simulated", GetNewPath("/"));
//return false;
};
};
// Get the Path when use VirtualPath in .Net or IIS
var GetNewPath = function (relative_path) {
var url = window.location.href;
if (url.substring(url.length - 1, url.length) == '/') {
url = url.substring(0, url.length - 1);
}
var url_parts = url.split('/');
if (relative_path.substring(0, 1) != '/') {
url_parts[url_parts.length - 2] = relative_path;
url_parts[url_parts.length - 1] = '';
}
else {
url_parts[url_parts.length - 2] = relative_path.substring(1);
url_parts[url_parts.length - 1] = '';
}
var new_page_absolute_path = url_parts.join('/');
if (new_page_absolute_path.substring(new_page_absolute_path.length - 1, new_page_absolute_path.length) == '/') {
new_page_absolute_path = new_page_absolute_path.substring(0, new_page_absolute_path.length - 1);
}
return new_page_absolute_path;
};
In the masterpage, the one used for the content pages:
<form runat="server">
<asp:ScriptManager ID="smDetail" EnableScriptLocalization="true" runat="server">
<Scripts>
<asp:ScriptReference Path="~/resources/js/timeout.js" />
</Scripts>
</asp:ScriptManager>
<ext:ResourceManager ID="rsManager01" runat="server" Theme="Gray" IDMode="Static">
<Listeners>
<DocumentReady Handler="detailTimeOut();" />
</Listeners>
</ext:ResourceManager>
<asp:ContentPlaceHolder ID="cpContent01" runat="server">
</asp:ContentPlaceHolder>
</form>
In the parent webform, so where I have a the main viewport and tabpanel (as in the examples.ext.net). Just need a stopCount(); in the success handler of the window where you request the credentials. In the frmTimeOut window I removed the HideLabel="true" tag, and add the FocusOnToFront="false" property (in november of the last year Equiman added it).
http://forums.ext.net/showthread.php...ible%28true%29
<form runat="server">
<asp:ScriptManager ID="smmaster" EnableScriptLocalization="true" runat="server">
<Scripts>
<asp:ScriptReference Path="~/resources/js/timeout.js" />
</Scripts>
</asp:ScriptManager>
<ext:ResourceManager ID="ResourceManager1" runat="server" >
<Listeners>
<DocumentReady Handler="masterTimeOut();stopCount();" />
</Listeners>
</ext:ResourceManager>
<ext:Viewport runat="server" Layout="BorderLayout">
.....
</ext:Viewport>
//This is the window for requesting again the credentials
<ext:Window
ID="wndL"
runat="server"
Closable="false"
Resizable="false"
Height="150"
Icon="Lock"
Title="Tu Sesion Caduco. Reingresa al Portal"
Draggable="false"
Width="400" Hidden="true"
Modal="true"
BodyPadding="5"
Layout="FormLayout" DefaultButton="btnLogin">
<Items>
<ext:TextField
ID="txtUser"
Name="txtUser"
runat="server"
FieldLabel="Usuario"
AllowBlank="false"
BlankText="Usuario" />
<ext:TextField
ID="txtPass"
Name="txtPass"
runat="server"
InputType="Password"
FieldLabel="Password"
AllowBlank="false"
BlankText="Password" />
</Items>
<Buttons>
<ext:Button ID="btnLogin" runat="server" Text="Login" Icon="Accept" Cls="default">
<Listeners>
<Click Handler="
if (!#{txtUser}.validate() || !#{txtPass}.validate()) {
Ext.Msg.alert('Error','Usuario y Password son requeridos');
// return false to prevent the btnLoginW_Click Ajax Click event from firing.
return false;
}" />
</Listeners>
<DirectEvents>
<Click OnEvent="btnLClick" Success="stopCount();">
<EventMask ShowMask="true" Msg="Verificando..." MinDelay="500" />
</Click>
</DirectEvents>
</ext:Button>
<ext:Button runat="server" Text="Logout" Icon="Cancel" Cls="default">
<DirectEvents>
<Click OnEvent="btnLOClick">
<EventMask ShowMask="true" Msg="Desconectado..." MinDelay="500" />
</Click>
</DirectEvents>
</ext:Button>
</Buttons>
</ext:Window>
//This is the window popup for timeout session reminder
<ext:Window
ID="frmTimeOut"
runat="server"
Width="350"
Height="50"
Modal="false"
Resizable="False"
Hidden="false"
Closable="false"
Layout="FormLayout" BodyStyle = "background-color: yellow;"
Draggable="false" FocusOnToFront="false"
Padding="12">
<Items>
<ext:Label ID="lblText" runat="server" Text="" AutoWidth="true" />
</Items>
</ext:Window>
</form>
My final question is: Why do we need to use this scriptmanager, does it exist a solution using just ext.net code? Using the asp:scriptmanager is mandatory to have a form runat="server" tag even if you dont need it:
<asp:ScriptManager ID="smmaster" EnableScriptLocalization="true" runat="server">
<Scripts>
<asp:ScriptReference Path="~/resources/js/timeout.js" />
</Scripts>
</asp:ScriptManager>