From: Argiris K. <be...@us...> - 2005-12-22 01:15:31
|
Update of /cvsroot/magicajax/magicajax/Core/UI In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7486/Core/UI Modified Files: AjaxControl.cs AjaxPage.cs AjaxUserControl.cs RenderedByScriptControl.cs Log Message: A bit of refactoring for the ajax events handling. --AjaxCall event is renamed to AjaxCallStart --AjaxControl/AjaxPage/AjaxUserControl invoke AjaxCallStart at Load event, PreWriteScript at PreRender, and AjaxCallEnd at Unload, during an Ajax callback --Some minor modifications to make extending AjaxControl a bit easier. Index: AjaxUserControl.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/AjaxUserControl.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** AjaxUserControl.cs 30 Nov 2005 12:22:29 -0000 1.9 --- AjaxUserControl.cs 22 Dec 2005 01:15:20 -0000 1.10 *************** *** 33,70 **** /// IAjaxCallEventHandler on your usercontrol to handle the AjaxCall events. /// </remarks> ! public class AjaxUserControl : System.Web.UI.UserControl, IAjaxCallEventHandler { private MagicAjaxContext _magicAjaxContext; /// <summary> ! /// Raised by MagicAjaxModule when an AjaxCall occurs /// </summary> ! public event EventHandler AjaxCall; /// <summary> ! /// Raised by MagicAjaxModule when an AjaxCallEnd occurs /// </summary> public event EventHandler AjaxCallEnd; /// <summary> ! /// Raises the AjaxCall event. /// </summary> ! /// <remarks> ! /// Called by MagicAjaxModule. ! /// </remarks> ! public void RaiseAjaxCallEvent() { ! OnAjaxCall (EventArgs.Empty); } /// <summary> ! /// Raises the AjaxCallEnd event. /// </summary> - /// <remarks> - /// Called by MagicAjaxModule. - /// </remarks> public void RaiseAjaxCallEndEvent() { ! OnAjaxCallEnd (EventArgs.Empty); } --- 33,86 ---- /// IAjaxCallEventHandler on your usercontrol to handle the AjaxCall events. /// </remarks> ! public class AjaxUserControl : System.Web.UI.UserControl, IAjaxCallEventHandler, IPreWriteScriptEventHandler { private MagicAjaxContext _magicAjaxContext; + private bool _isAjaxCall; + private bool _isPageNoStoreMode; /// <summary> ! /// Raised by the MagicAjaxModule and at Load event during an AjaxCall. /// </summary> ! public event EventHandler AjaxCallStart; /// <summary> ! /// Raised by the MagicAjaxModule and at PreRender event during an AjaxCall. ! /// </summary> ! public event EventHandler PreWriteScript; ! ! /// <summary> ! /// Raised by the MagicAjaxModule and at Unload event during an AjaxCall. /// </summary> public event EventHandler AjaxCallEnd; /// <summary> ! /// Implements the IAjaxCallEventHandler interface. It is called by the MagicAjaxModule. /// </summary> ! public void RaiseAjaxCallStartEvent() { ! SetAjaxIntrinsics(); ! OnAjaxCallStart(EventArgs.Empty); } /// <summary> ! /// Implements the IPreWriteScriptEventHandler interface. It is called by the MagicAjaxModule. ! /// </summary> ! public void RaisePreWriteScriptEvent() ! { ! OnPreWriteScript (EventArgs.Empty); ! } ! ! /// <summary> ! /// Implements the IAjaxCallEventHandler interface. It is called by the MagicAjaxModule. /// </summary> public void RaiseAjaxCallEndEvent() { ! OnAjaxCallEnd(EventArgs.Empty); ! } ! ! [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] ! public bool IsPageNoStoreMode ! { ! get { return _isPageNoStoreMode; } } *************** *** 75,79 **** public bool IsAjaxCall { ! get { return HttpContext.Current != null && MagicAjaxContext.Current.IsAjaxCallForPage(this.Page); } } --- 91,95 ---- public bool IsAjaxCall { ! get { return _isAjaxCall; } } *************** *** 83,103 **** } ! protected override void OnInit(EventArgs e) { ! _magicAjaxContext = MagicAjaxContext.Current; ! base.OnInit (e); } ! protected virtual void OnAjaxCall(EventArgs e) { ! if (AjaxCall != null) ! AjaxCall(this, e); } protected virtual void OnAjaxCallEnd(EventArgs e) { if (AjaxCallEnd != null) AjaxCallEnd(this, e); } } } \ No newline at end of file --- 99,151 ---- } ! protected override void OnLoad(EventArgs e) { ! SetAjaxIntrinsics(); ! ! base.OnLoad (e); ! if ( IsAjaxCall ) ! OnAjaxCallStart (e); } ! protected override void OnPreRender(EventArgs e) { ! base.OnPreRender (e); ! if ( IsAjaxCall ) ! OnPreWriteScript (e); ! } ! ! protected override void OnUnload(EventArgs e) ! { ! base.OnUnload (e); ! if ( IsAjaxCall ) ! OnAjaxCallEnd (e); ! } ! ! protected virtual void OnAjaxCallStart(EventArgs e) ! { ! if (AjaxCallStart != null) ! AjaxCallStart(this, e); ! } ! ! protected virtual void OnPreWriteScript(EventArgs e) ! { ! if (PreWriteScript != null) ! PreWriteScript(this, e); } protected virtual void OnAjaxCallEnd(EventArgs e) { + _magicAjaxContext = null; + if (AjaxCallEnd != null) AjaxCallEnd(this, e); } + + protected virtual void SetAjaxIntrinsics() + { + _magicAjaxContext = MagicAjaxContext.Current; + _isAjaxCall = ( HttpContext.Current != null && this.Page != null && MagicAjaxContext.Current.IsAjaxCallForPage(this.Page) ); + _isPageNoStoreMode = ( HttpContext.Current != null && MagicAjaxContext.Current.IsPageNoStoreMode ); + } } } \ No newline at end of file Index: AjaxPage.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/AjaxPage.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** AjaxPage.cs 30 Nov 2005 12:22:29 -0000 1.8 --- AjaxPage.cs 22 Dec 2005 01:15:20 -0000 1.9 *************** *** 33,79 **** /// implement the IAjaxCallEventHandler on your page to handle the AjaxCall events. /// </remarks> ! public class AjaxPage : System.Web.UI.Page, IAjaxCallEventHandler { private MagicAjaxContext _magicAjaxContext; /// <summary> ! /// Raised by MagicAjaxModule when an AjaxCall occurs /// </summary> ! public event EventHandler AjaxCall; /// <summary> ! /// Raised by MagicAjaxModule when an AjaxCallEnd occurs /// </summary> public event EventHandler AjaxCallEnd; /// <summary> ! /// Raises the AjaxCall event. /// </summary> ! /// <remarks> ! /// Called by MagicAjaxModule. ! /// </remarks> ! public void RaiseAjaxCallEvent() { ! OnAjaxCall (EventArgs.Empty); } /// <summary> ! /// Raises the AjaxCallEnd event. /// </summary> - /// <remarks> - /// Called by MagicAjaxModule. - /// </remarks> public void RaiseAjaxCallEndEvent() { ! OnAjaxCallEnd (EventArgs.Empty); } /// <summary> ! /// Determines if the page is being processed during an AjaxCall. /// </summary> [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool IsAjaxCall { ! get { return HttpContext.Current != null && MagicAjaxContext.Current.IsAjaxCallForPage(this); } } --- 33,95 ---- /// implement the IAjaxCallEventHandler on your page to handle the AjaxCall events. /// </remarks> ! public class AjaxPage : System.Web.UI.Page, IAjaxCallEventHandler, IPreWriteScriptEventHandler { private MagicAjaxContext _magicAjaxContext; + private bool _isAjaxCall; + private bool _isPageNoStoreMode; /// <summary> ! /// Raised by the MagicAjaxModule and at Load event during an AjaxCall. /// </summary> ! public event EventHandler AjaxCallStart; /// <summary> ! /// Raised by the MagicAjaxModule and at PreRender event during an AjaxCall. ! /// </summary> ! public event EventHandler PreWriteScript; ! ! /// <summary> ! /// Raised by the MagicAjaxModule and at Unload event during an AjaxCall. /// </summary> public event EventHandler AjaxCallEnd; /// <summary> ! /// Implements the IAjaxCallEventHandler interface. It is called by the MagicAjaxModule. /// </summary> ! public void RaiseAjaxCallStartEvent() { ! SetAjaxIntrinsics(); ! OnAjaxCallStart(EventArgs.Empty); } /// <summary> ! /// Implements the IPreWriteScriptEventHandler interface. It is called by the MagicAjaxModule. ! /// </summary> ! public void RaisePreWriteScriptEvent() ! { ! OnPreWriteScript (EventArgs.Empty); ! } ! ! /// <summary> ! /// Implements the IAjaxCallEventHandler interface. It is called by the MagicAjaxModule. /// </summary> public void RaiseAjaxCallEndEvent() { ! OnAjaxCallEnd(EventArgs.Empty); ! } ! ! [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] ! public bool IsPageNoStoreMode ! { ! get { return _isPageNoStoreMode; } } /// <summary> ! /// Determines if the control is being processed during an AjaxCall. /// </summary> [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool IsAjaxCall { ! get { return _isAjaxCall; } } *************** *** 83,103 **** } ! protected override void OnInit(EventArgs e) { ! _magicAjaxContext = MagicAjaxContext.Current; ! base.OnInit (e); } ! protected virtual void OnAjaxCall(EventArgs e) { ! if (AjaxCall != null) ! AjaxCall(this, e); } protected virtual void OnAjaxCallEnd(EventArgs e) { if (AjaxCallEnd != null) AjaxCallEnd(this, e); } } } \ No newline at end of file --- 99,151 ---- } ! protected override void OnLoad(EventArgs e) { ! SetAjaxIntrinsics(); ! ! base.OnLoad (e); ! if ( IsAjaxCall ) ! OnAjaxCallStart (e); } ! protected override void OnPreRender(EventArgs e) { ! base.OnPreRender (e); ! if ( IsAjaxCall ) ! OnPreWriteScript (e); ! } ! ! protected override void OnUnload(EventArgs e) ! { ! base.OnUnload (e); ! if ( IsAjaxCall ) ! OnAjaxCallEnd (e); ! } ! ! protected virtual void OnAjaxCallStart(EventArgs e) ! { ! if (AjaxCallStart != null) ! AjaxCallStart(this, e); ! } ! ! protected virtual void OnPreWriteScript(EventArgs e) ! { ! if (PreWriteScript != null) ! PreWriteScript(this, e); } protected virtual void OnAjaxCallEnd(EventArgs e) { + _magicAjaxContext = null; + if (AjaxCallEnd != null) AjaxCallEnd(this, e); } + + protected virtual void SetAjaxIntrinsics() + { + _magicAjaxContext = MagicAjaxContext.Current; + _isAjaxCall = ( HttpContext.Current != null && this.Page != null && MagicAjaxContext.Current.IsAjaxCallForPage(this) ); + _isPageNoStoreMode = ( HttpContext.Current != null && MagicAjaxContext.Current.IsPageNoStoreMode ); + } } } \ No newline at end of file Index: AjaxControl.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/AjaxControl.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** AjaxControl.cs 18 Dec 2005 16:44:46 -0000 1.10 --- AjaxControl.cs 22 Dec 2005 01:15:20 -0000 1.11 *************** *** 31,48 **** /// The base control for controls to get notified for AjaxCall events from the client. /// </summary> ! public abstract class AjaxControl : System.Web.UI.WebControls.WebControl, IAjaxCallEventHandler { private MagicAjaxContext _magicAjaxContext; private bool _isAjaxCall; private bool _isPageNoStoreMode; ! private bool _isInAjaxZone; /// <summary> ! /// Raised by the MagicAjaxModule. /// </summary> ! public event EventHandler AjaxCall; /// <summary> ! /// Raised by the MagicAjaxModule. /// </summary> public event EventHandler AjaxCallEnd; --- 31,53 ---- /// The base control for controls to get notified for AjaxCall events from the client. /// </summary> ! public abstract class AjaxControl : System.Web.UI.WebControls.WebControl, IAjaxCallEventHandler, IPreWriteScriptEventHandler { private MagicAjaxContext _magicAjaxContext; private bool _isAjaxCall; private bool _isPageNoStoreMode; ! private bool _isInAjaxScope; /// <summary> ! /// Raised by the MagicAjaxModule and at Load event during an AjaxCall. /// </summary> ! public event EventHandler AjaxCallStart; /// <summary> ! /// Raised by the MagicAjaxModule and at PreRender event during an AjaxCall. ! /// </summary> ! public event EventHandler PreWriteScript; ! ! /// <summary> ! /// Raised by the MagicAjaxModule and at Unload event during an AjaxCall. /// </summary> public event EventHandler AjaxCallEnd; *************** *** 51,57 **** /// Implements the IAjaxCallEventHandler interface. It is called by the MagicAjaxModule. /// </summary> ! public void RaiseAjaxCallEvent() { ! OnAjaxCall(EventArgs.Empty); } --- 56,72 ---- /// Implements the IAjaxCallEventHandler interface. It is called by the MagicAjaxModule. /// </summary> ! public void RaiseAjaxCallStartEvent() { ! SetAjaxIntrinsics(); ! OnAjaxCallStart(EventArgs.Empty); ! } ! ! /// <summary> ! /// Implements the IPreWriteScriptEventHandler interface. It is called by the MagicAjaxModule. ! /// </summary> ! public void RaisePreWriteScriptEvent() ! { ! SetAjaxAttributes(); ! OnPreWriteScript (EventArgs.Empty); } *************** *** 80,86 **** [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] ! public bool IsInAjaxZone { ! get { return _isInAjaxZone; } } --- 95,101 ---- [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] ! public bool IsInAjaxScope { ! get { return _isInAjaxScope; } } *************** *** 99,104 **** protected override void OnLoad(EventArgs e) { base.OnLoad (e); ! InitAjaxIntrinsics(); } --- 114,122 ---- protected override void OnLoad(EventArgs e) { + SetAjaxIntrinsics(); + base.OnLoad (e); ! if ( IsAjaxCall ) ! OnAjaxCallStart (e); } *************** *** 107,110 **** --- 125,129 ---- // Register 'AjaxCallObject.js' script MagicAjaxModule.EnableAjaxOnPage(this.Page); + SetAjaxAttributes(); #if NET_2_0 *************** *** 114,125 **** base.OnPreRender (e); } ! protected virtual void OnAjaxCall(EventArgs e) { ! InitAjaxIntrinsics(); ! if (AjaxCall != null) ! AjaxCall(this, e); } --- 133,157 ---- base.OnPreRender (e); + if ( IsAjaxCall ) + OnPreWriteScript (e); } ! protected override void OnUnload(EventArgs e) { ! base.OnUnload (e); ! if ( IsAjaxCall ) ! OnAjaxCallEnd (e); ! } ! protected virtual void OnAjaxCallStart(EventArgs e) ! { ! if (AjaxCallStart != null) ! AjaxCallStart(this, e); ! } ! ! protected virtual void OnPreWriteScript(EventArgs e) ! { ! if (PreWriteScript != null) ! PreWriteScript(this, e); } *************** *** 132,136 **** } ! protected virtual void InitAjaxIntrinsics() { _magicAjaxContext = MagicAjaxContext.Current; --- 164,168 ---- } ! protected virtual void SetAjaxIntrinsics() { _magicAjaxContext = MagicAjaxContext.Current; *************** *** 138,148 **** _isPageNoStoreMode = ( HttpContext.Current != null && MagicAjaxContext.Current.IsPageNoStoreMode ); ! string ajaxZoneID = Context.Request.Form["__AJAXZONE"]; ! _isInAjaxZone = ( ajaxZoneID == null || IsInAjaxZoneRecursive(this, ajaxZoneID) ); } ! private bool IsInAjaxZoneRecursive (Control control, string ajaxZoneID) { ! if (control.ClientID == ajaxZoneID) return true; --- 170,189 ---- _isPageNoStoreMode = ( HttpContext.Current != null && MagicAjaxContext.Current.IsPageNoStoreMode ); ! string ajaxScopeID = Context.Request.Form["__AJAXSCOPE"]; ! _isInAjaxScope = ( ajaxScopeID == null || IsInAjaxScopeRecursive(this, ajaxScopeID) ); } ! /// <summary> ! /// It is empty for the AjaxControl class. It is meant to be overriden ! /// by subclasses so that they set their MagicAjax attributes in their Attributes ! /// collection. ! /// </summary> ! protected virtual void SetAjaxAttributes() { ! } ! ! private bool IsInAjaxScopeRecursive (Control control, string ajaxScopeID) ! { ! if (control.ClientID == ajaxScopeID) return true; *************** *** 150,154 **** return false; ! return IsInAjaxZoneRecursive(control.Parent, ajaxZoneID); } } --- 191,195 ---- return false; ! return IsInAjaxScopeRecursive(control.Parent, ajaxScopeID); } } Index: RenderedByScriptControl.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/RenderedByScriptControl.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** RenderedByScriptControl.cs 18 Dec 2005 16:44:46 -0000 1.15 --- RenderedByScriptControl.cs 22 Dec 2005 01:15:20 -0000 1.16 *************** *** 69,73 **** /// its tag attributes using javascript. /// </remarks> ! public abstract class RenderedByScriptControl : AjaxControl, IPreWriteScriptEventHandler, IScriptWriter { protected abstract void RenderByScript(); --- 69,73 ---- /// its tag attributes using javascript. /// </remarks> ! public abstract class RenderedByScriptControl : AjaxControl, IScriptWriter { protected abstract void RenderByScript(); *************** *** 81,85 **** public event RenderStartEventHandler RenderStart; public event EventHandler RenderEnd; - public event EventHandler PreWriteScript; public override bool Visible --- 81,84 ---- *************** *** 223,230 **** } ! protected override void OnAjaxCall(EventArgs e) { _isHtmlRendered = false; ! base.OnAjaxCall(e); } --- 222,229 ---- } ! protected override void OnAjaxCallStart(EventArgs e) { _isHtmlRendered = false; ! base.OnAjaxCallStart(e); } *************** *** 286,302 **** /// <summary> - /// Called by MagicAjaxModule - /// </summary> - public virtual void RaisePreWriteScriptEvent() - { - OnPreWriteScript (EventArgs.Empty); - } - - /// <summary> /// If the tag html of the control is changed, send the attributes using javascript. /// </summary> public virtual void WriteScript() { ! if ( ! this.IsInAjaxZone ) return; --- 285,293 ---- /// <summary> /// If the tag html of the control is changed, send the attributes using javascript. /// </summary> public virtual void WriteScript() { ! if ( ! this.IsInAjaxScope ) return; *************** *** 388,397 **** RenderEnd(this, e); } - - protected virtual void OnPreWriteScript(EventArgs e) - { - if (PreWriteScript != null) - PreWriteScript(this, e); - } /// <summary> --- 379,382 ---- |