hello again.
well, i guess that you couldn't go into the pool without writing something to get you started. as i siad, this is a client behavior that can be applied to a control. it's very similar to the updateprogress code, but i've built it as behavior for 2 reasons: 1st, i'm a believer in that AJAS is client side; 2nd, because i think that transforming it into a server side component won't be too difficult (and this time I won't transform it so good luck). as allways, this code is as is and expect no support for it from me. having said that. here's page with the demo code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void h(object s, EventArgs a)
{
System.Threading.Thread.Sleep(3000);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager runat="server" id="manager" enablepartialrendering="true" />
<atlas:updatepanel runat="server" id="panel">
<contenttemplate>
<span>Partial postback:</span>
<%= DateTime.Now.ToString() %>
<asp:Button runat="server" ID="bt" Text="partial postback" OnClick="h" />
</contenttemplate>
</atlas:updatepanel>
<div id="info">
We're on a postback!
</div>
<script type="text/javascript">
Type.registerNamespace( "LA.ATLAS" );
LA.ATLAS.ProgressBehavior = function(){
LA.ATLAS.ProgressBehavior.initializeBase( this );
var _timer;
var _timerInterval = 1000;
var _timerHandler;
var _loadHandler;
var _propertyHandler;
this.get_timerInterval = function(){
return _timerInterval;
}
this.set_timerInterval = function( value ){
_timerInterval = value;
}
this.getDescriptor = function(){
var td = LA.ATLAS.ProgressBehavior.callBaseMethod( this, "getDescriptor" );
td.addProperty( "timerInterval", Number );
return td;
}
this.initialize = function(){
LA.ATLAS.ProgressBehavior.callBaseMethod( this, "initialize" );
this.control.element.style.display = "none";
//handle load event
_propertyHandler = Function.createDelegate( this, this._onPropChanged );
_loadHandler = Function.createDelegate( this, this._onLoadComplete );
Sys.Application.load.add( _loadHandler );
//create timer
_timerHandler = Function.createDelegate( this, this._onTimerTick );
_timer = new Sys.Timer();
_timer.set_interval( _timerInterval );
_timer.tick.add( _timerHandler );
_timer.set_enabled( false );
}
this.dispose = function(){
if( _timer ){
_timer.tick.remove( _timerHandler );
_timer.set_enabled( false );
_timer.dispose();
}
Sys.Application.load.remove( _loadHandler );
if( $object("_PageRequestManager") ){
$object("_PageRequestManager").propertyChanged.remove( _propertyHandler );
}
_timerHandler = null;
_loadHandler = null;
_propertyHandler = null;
LA.ATLAS.ProgressBehavior. callBaseMethod( this, "dispose" );
}
this._onLoadComplete = function( obj, args ){
$object("_PageRequestManager").propertyChanged.add( _propertyHandler );
}
this._onTimerTick = function( obj, args ){
this.control.element.style.display = "";
_timer.set_enabled( false );
}
this._onPropChanged = function( obj, args ){
if( args.get_propertyName() == "inPostBack" ){
if( $object("_PageRequestManager").get_inPostBack() ){
_timer.set_enabled( true );
}
else{
_timer.set_enabled(false);
this.control.element.style.display = "none";
}
}
}
}
LA.ATLAS.ProgressBehavior.registerSealedClass( "LA.ATLAS.ProgressBehavior", Sys.UI.Behavior );
Sys.TypeDescriptor.addType( "script", "progressBehavior", LA.ATLAS.ProgressBehavior );
</script>
</form>
</body>
</html>
<script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<components>
<control id="info">
<behaviors>
<progressBehavior timerInterval="2000" />
</behaviors>
</control>
</components>
</page>
</script>