I really like the way he designed it - and by also implementing partial postback capability (see his post's comments) - it really takes care of everything I need in a timeout control... except for one thing.. visibility. That's the only complaint I've ever heard is that when the template div is made visible - it's not always the most eye-catching element.
'Enter jQuery UI's Dialog (modal) plugin. I'd thought it'd be really nice to easily have a ui-themed dialog popup upon session timeout instead of simply showing a div. That'd definitely grab their attention instead of just a scrollTo + div.show() kind of approach.
This is my (work-in-process) solution.
We edit Travis's javascript file with the following changes:
At the bottom of the initialize: function() {.... section, we add the following code (simply so we can override it if desired):
this.initDialog();
That will allow the initialize routine to call our new initDialog function we're about to add (that we can easily override from the using application).
So now we add our new initDialog function (I added mine just after the _resetTimeout function):
// this will be the default Dialog if not overriden
initDialog: function(e) {
if (typeof jQuery.ui != 'undefined') {
var tsc = this;
$("#" + this._clientId).dialog({
autoOpen: false,
bgiframe: true,
modal: true,
buttons: {
Ok: function() {
$(this).dialog('close');
CallServer();
tsc._resetTimeout();
}
}
});
}
},
Now Initialize will call this function and setup our default dialog if we don't bother to override it. (Notice we're not going to do anything if the jQuery.ui isn't loaded.)
Next we change the existing showAboutToTimeout function to look like this:
showAboutToTimeout: function(e) {
if (typeof jQuery.ui != 'undefined')
$("#" + this._clientId).dialog('open');
else {
$get(this._clientId).style.display = 'block';
ScrollToElement($get(this._clientId));
}
window.focus();
},
So basically if jQuery.ui is loaded, we'll open our dialog (it should be initialized by now). If no jQuery.ui - we revert to Travis's original design.
One more slight change to the _resetTimeout function and we're done:
if (typeof jQuery.ui == 'undefined')
$get(this._clientId).style.display = 'none';
This just takes care of fully reverting to Travis's original design in case the jQuery UI isn't loaded. (Because our UI Dialog is going to close on it's own using the OK button function.
So that's it! Now the timeout control is capable of detecting if you have the jQuery IU loaded - and if so - display a dialog upon timeout. If no UI detected - it reverts back to Travis's original show/hide div design.
Here's an HTML example to use the new version of the Timeout control. Notice it still uses the original Template design for the dialog contents. *You have to add the title property to the Timeout control to set the Dialog window title:
<tsc:Timeout ID="Timeout1" runat="server" title="Session Expiring" Enabled="true" TimeoutURL="~/TimeOut.aspx" DisplayButton="false">
<Template>
<p>
<span class="ui-icon ui-icon-alert" style="float:left; margin: 1px 10px 20px 0;"></span>
Your session is about to Expire.
</p>
<br style="font-size:x-small;" />
<p>Click <b>OK</b> to continue your session.</p>
</Template>
</tsc:Timeout>
* Notice the dialog will be theme using whatever jQuery UI theme you are using.
And lastly, an example of how you'd override the default Dialog from the using application's HTML (if you wanted to):
<script type="text/javascript">
TSC.Timeout.Timeout.prototype.initDialog() {
if (typeof jQuery.ui != 'undefined') {
var tsc = this;
$("#" + this._clientId).dialog({
autoOpen: false,
bgiframe: true,
draggable: true,
modal: true,
buttons: {
Ok: function() {
$(this).dialog('close');
CallServer();
tsc._resetTimeout();
}
}
});
}
};
</script>
So there you have it - a fully jQuery UI Dialog enabled ASP.NET Session Timeout control! Thanks again to Travis Collins for his original design.
Click below for full Timeout Control project (source, dll's, etc).
NEW! Full working Web App solution demonstrating usage:
