From: Argiris K. <be...@us...> - 2005-11-14 18:50:55
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30932/Core Modified Files: AssemblyInfo.cs MagicAjax.csproj MagicAjaxModule.cs NoVerifyRenderingPage.cs StoredPageInfo.cs Web.config Added Files: AjaxCallHelper.cs Log Message: Replaced all "CallBack" references by "AjaxCall" Index: NoVerifyRenderingPage.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/NoVerifyRenderingPage.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NoVerifyRenderingPage.cs 11 Nov 2005 06:17:49 -0000 1.1 --- NoVerifyRenderingPage.cs 14 Nov 2005 18:50:43 -0000 1.2 *************** *** 32,36 **** /// </summary> /// <remarks> ! /// The controls that require to be inside a form cannot be rendered during a CallBack /// because of the VerifyRenderingInServerForm method of the Page. This class /// can be used to set the Page property of the controls and thus disabling --- 32,36 ---- /// </summary> /// <remarks> ! /// The controls that require to be inside a form cannot be rendered during an AjaxCall /// because of the VerifyRenderingInServerForm method of the Page. This class /// can be used to set the Page property of the controls and thus disabling *************** *** 56,60 **** if (control is IValidator) { ! if ( ! CallBackHelper.IsCallBack && HttpContext.Current.Handler is Page ) { // NoVerifyRenderingPage is used event during normal rendering, --- 56,60 ---- if (control is IValidator) { ! if ( ! AjaxCallHelper.IsAjaxCall && HttpContext.Current.Handler is Page ) { // NoVerifyRenderingPage is used event during normal rendering, *************** *** 66,70 **** } ! // The error message doesn't get visible during a CallBack. // Do it manually. IValidator valid = (IValidator) control; --- 66,70 ---- } ! // The error message doesn't get visible during an AjaxCall. // Do it manually. IValidator valid = (IValidator) control; Index: MagicAjax.csproj =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjax.csproj,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MagicAjax.csproj 11 Nov 2005 06:17:49 -0000 1.1 --- MagicAjax.csproj 14 Nov 2005 18:50:43 -0000 1.2 *************** *** 95,104 **** <Include> <File ! RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "CallBackHelper.cs" SubType = "Code" BuildAction = "Compile" --- 95,104 ---- <Include> <File ! RelPath = "AjaxCallHelper.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" *************** *** 144,148 **** /> <File ! RelPath = "Interfaces\ICallBackEventHandler.cs" SubType = "Code" BuildAction = "Compile" --- 144,148 ---- /> <File ! RelPath = "Interfaces\IAjaxCallEventHandler.cs" SubType = "Code" BuildAction = "Compile" *************** *** 164,168 **** /> <File ! RelPath = "script\CallBackObject.js" BuildAction = "EmbeddedResource" /> --- 164,168 ---- /> <File ! RelPath = "script\AjaxCallObject.js" BuildAction = "EmbeddedResource" /> Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/AssemblyInfo.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssemblyInfo.cs 11 Nov 2005 06:17:49 -0000 1.1 --- AssemblyInfo.cs 14 Nov 2005 18:50:43 -0000 1.2 *************** *** 21,25 **** #if NET_2_0 //Webresources ! [assembly: WebResourceAttribute("MagicAjax.script.CallBackObject.js", "text/javascript")] #endif --- 21,25 ---- #if NET_2_0 //Webresources ! [assembly: WebResourceAttribute("MagicAjax.script.AjaxCallObject.js", "text/javascript")] #endif Index: StoredPageInfo.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/StoredPageInfo.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StoredPageInfo.cs 11 Nov 2005 06:17:49 -0000 1.1 --- StoredPageInfo.cs 14 Nov 2005 18:50:43 -0000 1.2 *************** *** 10,14 **** { private Page _page; ! private int _callBacksCount; private DateTime _lastAccess; --- 10,14 ---- { private Page _page; ! private int _ajaxCallsCount; private DateTime _lastAccess; *************** *** 18,25 **** } ! public int CallBacksCount { ! get { return _callBacksCount; } ! set { _callBacksCount = value; } } --- 18,25 ---- } ! public int AjaxCallsCount { ! get { return _ajaxCallsCount; } ! set { _ajaxCallsCount = value; } } *************** *** 33,37 **** { _page = page; ! _callBacksCount = 0; _lastAccess = DateTime.Now; } --- 33,37 ---- { _page = page; ! _ajaxCallsCount = 0; _lastAccess = DateTime.Now; } --- NEW FILE: AjaxCallHelper.cs --- #region LGPL License /* MagicAjax Library Copyright (C) 2005 MagicAjax Project Team This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #endregion using System; using System.Configuration; using System.Web; using System.Web.UI; using System.Collections; namespace MagicAjax { /// <summary> /// Defines the various AjaxCall types /// </summary> public enum AjaxCallType { /// <summary> /// Client didn't invoke an AjaxCall /// </summary> None, /// <summary> /// Standard AjaxCall invoked by a control on the page /// </summary> Control, /// <summary> /// AjaxCall invoked by the AjaxCallTimer /// </summary> Timer } /// <summary> /// Helper functions for AjaxCall handling. /// </summary> public sealed class AjaxCallHelper { private AjaxCallHelper() { } private static System.Text.StringBuilder sbScript = null; #region Static Properties /// <summary> /// Returns the AjaxCall type, suitable for a switch block. /// </summary> public static AjaxCallType AjaxCallType { get { if ( IsAjaxCallTimer ) return AjaxCallType.Timer; else if ( IsAjaxCall ) return AjaxCallType.Control; else return AjaxCallType.None; } } /// <summary> /// Determines whether an AjaxCall was invoked on the server by the client. /// </summary> public static bool IsAjaxCall { get { return ( MagicAjaxModule.Instance.IsAjaxCall ); } } /// <summary> /// Gets the argument string the was sent by the client. /// </summary> public static string AjaxCallArgument { get { if ( IsAjaxCall ) return MagicAjaxModule.Instance.Form["__EVENTARGUMENT"]; else return null; } } /// <summary> /// Determines whether the AjaxCall occured by the AjaxCallTimer. /// </summary> /// <remarks> /// See the remarks of the SetAjaxCallTimerInterval method. /// </remarks> public static bool IsAjaxCallTimer { get { return ( MagicAjaxModule.Instance.Form["__EVENTTARGET"] == "__AJAX_AjaxCallTimer" ); } } /// <summary> /// Gets the name of the javascript function that is used for AjaxCalls from /// the client. /// </summary> public static string AjaxCallClientFunction { get { return "AJAXCbo.DoAjaxCall"; } } /// <summary> /// Included for convenience. /// </summary> public static HttpContext Context { get { return System.Web.HttpContext.Current; } } /// <summary> /// Included for convenience. /// </summary> public static HttpResponse Response { get { HttpResponse hr = System.Web.HttpContext.Current.Response; if (hr == null) throw new MagicAjaxException("AjaxCallHelper could not access current HttpResponse object"); return hr; } } /// <summary> /// Included for convenience. /// </summary> public static HttpRequest Request { get { HttpRequest hr = System.Web.HttpContext.Current.Request; if (hr == null) throw new MagicAjaxException("AjaxCallHelper could not access current HttpRequest object"); return hr; } } #endregion #region Static Methods /// <summary> /// Obtains a reference to a client-side script function that causes, when invoked, /// the control to raise an AjaxCall event to the server. This method also passes /// a parameter to the server control that performs the post-back processing on /// the server. /// </summary> /// <example> /// // Replaces the submit function of the button with the AjaxCall invoking function. /// btnSend.Attributes.Add ("onclick", AjaxCallHelper.GetAjaxCallEventReference(btnSend) + " return false;"); /// </example> /// <param name="control"></param> /// <param name="argument"></param> /// <returns></returns> public static string GetAjaxCallEventReference(Control control, string argument, bool isAsynchronous) { if (control == null) throw new ArgumentNullException("control"); return String.Format("{0}('{1}','{2}','{3}');", AjaxCallClientFunction, control.UniqueID, argument, (isAsynchronous) ? "async" : "sync"); } /// <summary> /// Obtains a reference to a client-side script function that causes, when invoked, /// the control to raise an AjaxCall event to the server. This method also passes /// a parameter to the server control that performs the post-back processing on /// the server. /// </summary> /// <example> /// // Replaces the submit function of the button with the AjaxCall invoking function. /// btnSend.Attributes.Add ("onclick", AjaxCallHelper.GetAjaxCallEventReference(btnSend) + " return false;"); /// </example> /// <param name="control"></param> /// <param name="argument"></param> /// <returns></returns> public static string GetAjaxCallEventReference(Control control, string argument) { if (control == null) throw new ArgumentNullException("control"); return GetAjaxCallEventReference(control, argument, true); } /// <summary> /// Obtains a reference to a client-side script function that causes, when invoked, /// the control to raise an AjaxCall event to the server. /// </summary> /// <example> /// // Replaces the submit function of the button with the AjaxCall invoking function. /// btnSend.Attributes.Add ("onclick", AjaxCallHelper.GetAjaxCallEventReference(btnSend) + " return false;"); /// </example> /// <param name="control"></param> /// <returns></returns> public static string GetAjaxCallEventReference(Control control) { return GetAjaxCallEventReference(control, "", true); } /// <summary> /// Appends javascript: to the beginning of the return from a /// GetAjaxCallEventReference call to allow hyperlink AjaxCall processing on the /// server. /// </summary> /// <param name="control"></param> /// <param name="argument"></param> /// <returns></returns> public static string GetAjaxCallClientHyperlink(Control control, string argument) { return String.Format("javascript:{0}", GetAjaxCallEventReference(control, argument)); } /// <summary> /// Defines the time between repeated automatic AjaxCalls of the page. /// </summary> /// <param name="milliSeconds">Set it to zero in order to disable AjaxCallTimer</param> public static void SetAjaxCallTimerInterval(int milliSeconds) { if (milliSeconds > 0) { if ( IsAjaxCall ) Write (String.Format("AJAXCbo.SetIntervalForAjaxCall({0});", milliSeconds)); else { //EnableAjaxOnPage(); Page page = (Page) HttpContext.Current.Handler; page.RegisterStartupScript ("AJAX_AjaxCallTimer_SCRIPT", String.Format("<script language=\"javascript\">AJAXCbo.SetIntervalForAjaxCall({0});</script>", milliSeconds)); } } else { if ( IsAjaxCall ) Write ("AJAXCbo.ClearIntervalForAjaxCall();"); else throw new MagicAjaxException("AjaxCallTimer can be cleared only during an AjaxCall."); } } /// <summary> /// Resolves relative url's (starting with "~"). /// Use this when Control.ResolveUrl() is not available. /// </summary> /// <param name="url"></param> /// <returns></returns> public static string ResolveUrl(string url) { if (url != null && url.StartsWith("~") && HttpContext.Current != null) { string appPath = HttpContext.Current.Request.ApplicationPath.Length > 1 ? HttpContext.Current.Request.ApplicationPath : string.Empty; url = appPath + url.Substring(1); } return url; } #endregion #region Static Methods for javascript writing /// <summary> /// Produces the javascript that redirects to a url. /// </summary> /// <param name="url"></param> public static void Redirect(string url) { Response.Clear(); Write(String.Format("window.location.href=\"{0}\";\r\n", ResolveUrl(url))); End(); } /// <summary> /// Produces the javascript that will set the attributes of a control. /// </summary> /// <remarks> /// The attributes must be of this format: /// "attrib1=value1|attrib2=value2|attrib3=value3" /// </remarks> /// <param name="clientID">ClientID of the control</param> /// <param name="attributes">Formatted list of attributes</param> public static void WriteSetAttributesOfControl(string clientID, string attributes) { Write( String.Format("AJAXCbo.SetAttributesOfControl(\"{0}\",\"{1}\");\r\n", clientID, attributes) ); } /// <summary> /// Produces the javascript that will a new element on the page. /// </summary> /// <param name="parentID">The id of the element that will contain the new element</param> /// <param name="elementID">The id of the new element</param> /// <param name="html">The innerHTML of the new element</param> /// <param name="beforeElemID">The id of the element that the new element must be inserted before it. Use null to append the new element at the end of the parent element</param> public static void WriteAddElementScript(string parentID, string tagName, string elementID, string html, string beforeElemID) { string before = (beforeElemID != null) ? String.Format("\"{0}\"", beforeElemID) : "null"; Write( String.Format("AJAXCbo.AddElementScript(\"{0}\",\"{1}\",\"{2}\",{3},{4});\r\n", parentID, tagName, elementID, EncodeString(html), before) ); } /// <summary> /// Provides the javascript that will remove an existing element from the page. /// </summary> /// <param name="parentID">The id of the element that contains the element to be removed</param> /// <param name="elementID">The id of the element to be removed</param> public static void WriteRemoveElementScript(string parentID, string elementID) { Write( String.Format("AJAXCbo.RemoveElementScript(\"{0}\",\"{1}\");\r\n", parentID, elementID) ); } /// <summary> /// Provides the javascript that will set the value of a field on the page. /// </summary> /// <remarks> /// Use this if you want to manipulate, during AjaxCall, a hidden field previously /// registered by the Page.RegisterHiddenField method. /// </remarks> /// <param name="fieldName"></param> /// <param name="fieldValue"></param> public static void WriteSetFieldScript(string fieldName, string fieldValue) { Write( String.Format("AJAXCbo.SetFieldScript(\"{0}\",{1});\r\n", fieldName, EncodeString(fieldValue)) ); } /// <summary> /// Provides the javascript that will se the innerHTML of an element of the page. /// </summary> /// <param name="html"></param> /// <param name="elementID">The id of the element of the page</param> public static void WriteSetHtmlOfElementScript(string html, string elementID) { Write( String.Format("AJAXCbo.SetHtmlOfElementScript({0},\"{1}\");\r\n", EncodeString(html), elementID) ); } public static void WriteSetHtmlOfPageScript(string html) { Write ( String.Format("AJAXCbo.SetHtmlOfPage({0});\r\n", EncodeString(html)) ); } public static void WriteSetVisibilityOfElementScript(string elementID, bool visible) { Write ( String.Format("AJAXCbo.SetVisibilityOfElement(\"{0}\",{1});\r\n", elementID ,visible.ToString().ToLower()) ); } /// <summary> /// Provides the javascript that will invoke an alert message box. /// </summary> /// <param name="message"></param> public static void WriteAlert(string message) { Write ( String.Format("AJAXCbo.Alert({0});\r\n", EncodeString(message)) ); } /// <summary> /// It appends a "'AJAX_LOADING_OK';" string to the end, so that the client /// knows that the loading of the AjaxCall javascript data wasn't aborted, /// but they were fully loaded. /// </summary> /// <remarks> /// Called by the End method. /// </remarks> internal static void WriteEndSignature() { Write ("'AJAX_LOADING_OK';"); } /// <summary> /// Converts a string to a javascript string. /// </summary> /// <example> /// AjaxCallHelper.Write (String.Format("alert({0});", AjaxCallHelper.EncodeString("Alert invoked by javascript."))); /// </example> /// <param name="str"></param> /// <returns></returns> public static string EncodeString(string str) { //TODO: use 1 regular expression (faster) System.Text.StringBuilder sb = new System.Text.StringBuilder(str); sb.Replace("\\", "\\\\"); sb.Replace("\"", "\\\""); sb.Replace("\r", "\\r"); sb.Replace("\n", "\\n"); sb.Replace("\t", "\\t"); sb.Insert(0, '\"'); sb.Append('\"'); return sb.ToString(); } /// <summary> /// Writes to the Response. Included for convenience. /// </summary> /// <remarks> /// Use this method if you want to send custom javascript code for the client to execute. /// Use EncodeString if you want to append a string for your javascript code. /// </remarks> /// <example> /// AjaxCallHelper.Write (String.Format("var span = document.getElementById('{0}');", label.ClientID)); /// AjaxCallHelper.Write (String.Format("span.innerHTML = {0});", AjaxCallHelper.EncodeString("Changed by javascript"))); /// </example> /// <param name="text"></param> public static void Write( string text) { // Use the string builder //Response.Write (text + "\r\n"); sbScript.Append (text + "\r\n"); } internal static void Init() { HttpResponse hr = AjaxCallHelper.Response; hr.StatusCode = 200; hr.StatusDescription = "OK"; sbScript = new System.Text.StringBuilder(); } /// <summary> /// Use this method instead of Response.End during an AjaxCall. /// </summary> /// <remarks> /// Writes the End signature, ends the writing to the Response and causes /// CompleteRequest on the application. /// </remarks> public static void End() { WriteEndSignature(); HttpResponse hr = AjaxCallHelper.Response; hr.Clear(); hr.Write (sbScript.ToString()); MagicAjaxModule.Instance.CompletedAjaxCall = true; hr.Flush(); hr.End(); } #endregion } } Index: Web.config =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Web.config,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Web.config 11 Nov 2005 06:17:49 -0000 1.1 --- Web.config 14 Nov 2005 18:50:43 -0000 1.2 *************** *** 8,15 **** <!-- MagicAjax configuration : ! [Optional] callBackScriptPath - Alternative path for "CallBackObject.js" ! If omitted, the embedded "CallBackObject.js" file is used (default). ! example: <magicAjax callBackScriptPath="~/script" /> ! pageStore/mode - "NoStore" : Doesn't keep the page object, it is recreated for each callback "Session" : Saves the page object in session, works only for "InProc" SessionState "Cache" : Saves the page object in cache --- 8,15 ---- <!-- MagicAjax configuration : ! [Optional] ajaxCallScriptPath - Alternative path for "AjaxCallObject.js" ! If omitted, the embedded "AjaxCallObject.js" file is used (default). ! example: <magicAjax ajaxCallScriptPath="~/script" /> ! pageStore/mode - "NoStore" : Doesn't keep the page object, it is recreated for each AjaxCall "Session" : Saves the page object in session, works only for "InProc" SessionState "Cache" : Saves the page object in cache Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MagicAjaxModule.cs 14 Nov 2005 16:16:56 -0000 1.4 --- MagicAjaxModule.cs 14 Nov 2005 18:50:43 -0000 1.5 *************** *** 38,42 **** { /// <summary> ! /// It handles a CallBack request from the client and sends the appropriate javascript. /// </summary> /// <remarks> --- 38,42 ---- { /// <summary> ! /// It handles an AjaxCall request from the client and sends the appropriate javascript. /// </summary> /// <remarks> *************** *** 69,76 **** #endregion ! private bool _isCallBack = false; private NameValueCollection _form; private MagicAjaxConfiguration _config; ! private bool _completedCallBack; private PageFilter _filter; private HttpContext _context; --- 69,76 ---- #endregion ! private bool _isAjaxCall = false; private NameValueCollection _form; private MagicAjaxConfiguration _config; ! private bool _completedAjaxCall; private PageFilter _filter; private HttpContext _context; *************** *** 80,86 **** #region Properties ! public bool IsCallBack { ! get { return _isCallBack; } } --- 80,86 ---- #region Properties ! public bool IsAjaxCall { ! get { return _isAjaxCall; } } *************** *** 95,102 **** } ! public bool CompletedCallBack { ! get { return _completedCallBack; } ! set { _completedCallBack = value; } } #endregion --- 95,102 ---- } ! public bool CompletedAjaxCall { ! get { return _completedAjaxCall; } ! set { _completedAjaxCall = value; } } #endregion *************** *** 133,151 **** /// This method is called by controls that inherit from AjaxControl. /// Depending on the configuration options of MagicAjax, the page object may ! /// be stored so that MagicAjaxModule can retrieve it at a CallBack. /// </remarks> public virtual void EnableAjaxOnPage(Page page) { ! if ( _isCallBack ) return; string STARTUP_SCRIPT_FORMAT = @" <script language='javascript'> if (typeof(AJAXCbo) == 'undefined') ! alert(""Unable to find script library '{0}/{1}'. Copy the file to the required location, or change the 'callBackScriptPath' setting at magicAjax section of web.config.""); else ! AJAXCbo.HookCallBack({2}); </script>"; ! if (!page.IsClientScriptBlockRegistered( "CALLBACK_FOR_AJAX" )) { // Provides the location of the script file. --- 133,151 ---- /// This method is called by controls that inherit from AjaxControl. /// Depending on the configuration options of MagicAjax, the page object may ! /// be stored so that MagicAjaxModule can retrieve it at an AjaxCall. /// </remarks> public virtual void EnableAjaxOnPage(Page page) { ! if ( _isAjaxCall ) return; string STARTUP_SCRIPT_FORMAT = @" <script language='javascript'> if (typeof(AJAXCbo) == 'undefined') ! alert(""Unable to find script library '{0}/{1}'. Copy the file to the required location, or change the 'ajaxCallScriptPath' setting at magicAjax section of web.config.""); else ! AJAXCbo.HookAjaxCall({2}); </script>"; ! if (!page.IsClientScriptBlockRegistered( "AJAXCALL_FOR_MAGICAJAX" )) { // Provides the location of the script file. *************** *** 153,165 **** string includeScript; ! // If script location is null, use embedded CallBackObject.js file if (location == null) { #if NET_2_0 ! //use the webresource url for CallBackObject.js ! includeScript = String.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", page.ClientScript.GetWebResourceUrl(typeof(MagicAjaxModule), "MagicAjax.script.CallBackObject.js")); #else ! //read and output the embedded CallBackObject.js file from the manifest ! using (System.IO.StreamReader reader = new System.IO.StreamReader(typeof(MagicAjaxModule).Assembly.GetManifestResourceStream("MagicAjax.script.CallBackObject.js"))) { includeScript = String.Format("<script type=\"text/javascript\">\r\n<!--\r\n{0}\r\n//-->\r\n</script>", reader.ReadToEnd()); --- 153,165 ---- string includeScript; ! // If script location is null, use embedded AjaxCallObject.js file if (location == null) { #if NET_2_0 ! //use the webresource url for AjaxCallObject.js ! includeScript = String.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", page.ClientScript.GetWebResourceUrl(typeof(MagicAjaxModule), "MagicAjax.script.AjaxCallObject.js")); #else ! //read and output the embedded AjaxCallObject.js file from the manifest ! using (System.IO.StreamReader reader = new System.IO.StreamReader(typeof(MagicAjaxModule).Assembly.GetManifestResourceStream("MagicAjax.script.AjaxCallObject.js"))) { includeScript = String.Format("<script type=\"text/javascript\">\r\n<!--\r\n{0}\r\n//-->\r\n</script>", reader.ReadToEnd()); *************** *** 170,179 **** { // Point to external script source file ! includeScript = String.Format("<script type=\"text/javascript\" src=\"{0}/{1}\"></script>", location, "CallBackObject.js"); } ! page.RegisterClientScriptBlock( "CALLBACK_FOR_AJAX", includeScript ); bool pageIsStored = (_config.PageStore.Mode != PageStoreMode.NoStore); ! page.RegisterStartupScript( "CALLBACK_HOOK", String.Format(STARTUP_SCRIPT_FORMAT, location, "CallBackObject.js", pageIsStored.ToString().ToLower())); if ( pageIsStored ) --- 170,179 ---- { // Point to external script source file ! includeScript = String.Format("<script type=\"text/javascript\" src=\"{0}/{1}\"></script>", location, "AjaxCallObject.js"); } ! page.RegisterClientScriptBlock( "AJAXCALL_FOR_MAGICAJAX", includeScript ); bool pageIsStored = (_config.PageStore.Mode != PageStoreMode.NoStore); ! page.RegisterStartupScript( "AJAXCALL_HOOK", String.Format(STARTUP_SCRIPT_FORMAT, location, "AjaxCallObject.js", pageIsStored.ToString().ToLower())); if ( pageIsStored ) *************** *** 321,325 **** // Firefox requests the page first and then sends the unload page request, // so check to see if the page we are going to remove is just created. ! if (storedInfo.CallBacksCount == 0 && DateTime.Now-storedInfo.LastAccess < TimeSpan.FromSeconds(5)) return; --- 321,325 ---- // Firefox requests the page first and then sends the unload page request, // so check to see if the page we are going to remove is just created. ! if (storedInfo.AjaxCallsCount == 0 && DateTime.Now-storedInfo.LastAccess < TimeSpan.FromSeconds(5)) return; *************** *** 399,404 **** } ! _isCallBack = false; ! _completedCallBack = false; Page requestPage = (Page) _context.Handler; --- 399,404 ---- } ! _isAjaxCall = false; ! _completedAjaxCall = false; Page requestPage = (Page) _context.Handler; *************** *** 409,427 **** #endif ! // Continue only if it is a postback or a callback if ( "GET" == _request.HttpMethod ) return; ! _isCallBack = (_request.Form["__AJAX_CALLBACK"] != null); _form = _request.Form; if ( PageStoreMode.NoStore == _config.PageStore.Mode ) { ! if ( _isCallBack ) { _filter = new PageFilter(_response.Filter); _response.Filter = _filter; ! CallBackHelper.Init(); _context.Handler.ProcessRequest (_context); --- 409,427 ---- #endif ! // Continue only if it is a postback or an AjaxCall if ( "GET" == _request.HttpMethod ) return; ! _isAjaxCall = (_request.Form["__AJAXCALL"] != null); _form = _request.Form; if ( PageStoreMode.NoStore == _config.PageStore.Mode ) { ! if ( _isAjaxCall ) { _filter = new PageFilter(_response.Filter); _response.Filter = _filter; ! AjaxCallHelper.Init(); _context.Handler.ProcessRequest (_context); *************** *** 431,435 **** if (vsValue != null && _form["__VIEWSTATE"] != vsValue) { ! CallBackHelper.WriteSetFieldScript("__VIEWSTATE", vsValue); } --- 431,435 ---- if (vsValue != null && _form["__VIEWSTATE"] != vsValue) { ! AjaxCallHelper.WriteSetFieldScript("__VIEWSTATE", vsValue); } *************** *** 480,491 **** __wpm.zones = new Array(); }"; ! CallBackHelper.Write(wpm_Dispose_script); // Send script to setup webpartmanager drag&drop + webpartmenu's ! CallBackHelper.Write(wpmValue); } } #endif ! CallBackHelper.End(); } } --- 480,491 ---- __wpm.zones = new Array(); }"; ! AjaxCallHelper.Write(wpm_Dispose_script); // Send script to setup webpartmanager drag&drop + webpartmenu's ! AjaxCallHelper.Write(wpmValue); } } #endif ! AjaxCallHelper.End(); } } *************** *** 498,502 **** if (pageKey == null) { ! if ( _isCallBack ) throw new MagicAjaxException(String.Format("Hidden field '{0}' wasn't found. Page isn't AJAX enabled.", PageKeyFieldName)); else --- 498,502 ---- if (pageKey == null) { ! if ( _isAjaxCall ) throw new MagicAjaxException(String.Format("Hidden field '{0}' wasn't found. Page isn't AJAX enabled.", PageKeyFieldName)); else *************** *** 510,517 **** // Have the browser do a refresh. // It will stop the current execution and will throw Application_EndRequest event ! CallBackHelper.Redirect (_request.RawUrl); } ! if ( ! _isCallBack ) { // PostBack. Will replace the recreated controls with the stored ones --- 510,517 ---- // Have the browser do a refresh. // It will stop the current execution and will throw Application_EndRequest event ! AjaxCallHelper.Redirect (_request.RawUrl); } ! if ( ! _isAjaxCall ) { // PostBack. Will replace the recreated controls with the stored ones *************** *** 520,529 **** else { ! // CallBack _filter = new PageFilter(_response.Filter); _response.Filter = _filter; ! if (_currentPageInfo.CallBacksCount == 0 && _currentPageInfo.Page.Validators.Count == 0) { --- 520,529 ---- else { ! // AjaxCall _filter = new PageFilter(_response.Filter); _response.Filter = _filter; ! if (_currentPageInfo.AjaxCallsCount == 0 && _currentPageInfo.Page.Validators.Count == 0) { *************** *** 534,545 **** } ! CallBackHelper.Init(); ! ProcessCallBack(_currentPageInfo.Page); ! _currentPageInfo.CallBacksCount++; _currentPageInfo.LastAccess = DateTime.Now; ! CallBackHelper.End(); } } --- 534,545 ---- } ! AjaxCallHelper.Init(); ! ProcessAjaxCall(_currentPageInfo.Page); ! _currentPageInfo.AjaxCallsCount++; _currentPageInfo.LastAccess = DateTime.Now; ! AjaxCallHelper.End(); } } *************** *** 559,563 **** /// </summary> /// <remarks> ! /// During a callback it checks if the request was ended because of a /// Response.Redirect or a Server.Transfer and sends the appropriate javascript /// for each case. --- 559,563 ---- /// </summary> /// <remarks> ! /// During an AjaxCall it checks if the request was ended because of a /// Response.Redirect or a Server.Transfer and sends the appropriate javascript /// for each case. *************** *** 567,574 **** protected virtual void Application_EndRequest(object sender, EventArgs e) { ! if ( ! _isCallBack || _completedCallBack ) return; ! // There was a Response.Redirect or Server.Transfer during callback HttpApplication application = (HttpApplication) sender; --- 567,574 ---- protected virtual void Application_EndRequest(object sender, EventArgs e) { ! if ( ! _isAjaxCall || _completedAjaxCall ) return; ! // There was a Response.Redirect or Server.Transfer during AjaxCall HttpApplication application = (HttpApplication) sender; *************** *** 578,599 **** { // Handle Response.Redirect ! CallBackHelper.Redirect (response.RedirectLocation); } else { // Handle Server.Transfer ! CallBackHelper.Init(); string html = _filter.GetHtmlPage(); ! CallBackHelper.WriteSetHtmlOfPageScript (html); ! CallBackHelper.End(); } } /// <summary> ! /// Raises the callback events on the Page and the child controls, /// and invokes the IScriptWriter controls. /// </summary> /// <param name="page"></param> ! protected virtual void ProcessCallBack(Page page) { ReadOnlyArrayList postDataChangedControls; --- 578,599 ---- { // Handle Response.Redirect ! AjaxCallHelper.Redirect (response.RedirectLocation); } else { // Handle Server.Transfer ! AjaxCallHelper.Init(); string html = _filter.GetHtmlPage(); ! AjaxCallHelper.WriteSetHtmlOfPageScript (html); ! AjaxCallHelper.End(); } } /// <summary> ! /// Raises the AjaxCall events on the Page and the child controls, /// and invokes the IScriptWriter controls. /// </summary> /// <param name="page"></param> ! protected virtual void ProcessAjaxCall(Page page) { ReadOnlyArrayList postDataChangedControls; *************** *** 605,611 **** handler.RaisePostDataChangedEvent(); ! RaiseCallBackEvent (page); ! if ( CallBackHelper.CallBackType == CallBackType.Control ) { string target = _form["__EVENTTARGET"]; --- 605,611 ---- handler.RaisePostDataChangedEvent(); ! RaiseAjaxCallEvent (page); ! if ( AjaxCallHelper.AjaxCallType == AjaxCallType.Control ) { string target = _form["__EVENTTARGET"]; *************** *** 638,656 **** /// <summary> ! /// Raises callback event on the supplied control and its children. /// </summary> /// <remarks> /// This is a recursive method. It goes through the control collection tree ! /// and raises the callback event on all the controls that implement the ! /// ICallBackEventHandler interface. /// </remarks> /// <param name="control"></param> ! protected virtual void RaiseCallBackEvent (Control control) { ! if (control is ICallBackEventHandler) ! ((ICallBackEventHandler) control).RaiseCallBackEvent(); for (int i=0; i < control.Controls.Count; i++) ! RaiseCallBackEvent (control.Controls[i]); } --- 638,656 ---- /// <summary> ! /// Raises AjaxCall event on the supplied control and its children. /// </summary> /// <remarks> /// This is a recursive method. It goes through the control collection tree ! /// and raises the AjaxCall event on all the controls that implement the ! /// IAjaxCallEventHandler interface. /// </remarks> /// <param name="control"></param> ! protected virtual void RaiseAjaxCallEvent (Control control) { ! if (control is IAjaxCallEventHandler) ! ((IAjaxCallEventHandler) control).RaiseAjaxCallEvent(); for (int i=0; i < control.Controls.Count; i++) ! RaiseAjaxCallEvent (control.Controls[i]); } *************** *** 692,696 **** /// <summary> ! /// Loads form post data on controls during a CallBack. /// </summary> protected virtual ArrayList LoadFormDataOnChildren (Control control) --- 692,696 ---- /// <summary> ! /// Loads form post data on controls during an AjaxCall. /// </summary> protected virtual ArrayList LoadFormDataOnChildren (Control control) *************** *** 717,721 **** // For some strange reason, if the RadioButtonList selection // changes, the SelectedIndexChanged event is invoked every time ! // a callback occurs. So, do a manual check. RadioButtonList rbList = (RadioButtonList) con; if (_form[rbList.UniqueID] != rbList.SelectedValue) --- 717,721 ---- // For some strange reason, if the RadioButtonList selection // changes, the SelectedIndexChanged event is invoked every time ! // an AjaxCall occurs. So, do a manual check. RadioButtonList rbList = (RadioButtonList) con; if (_form[rbList.UniqueID] != rbList.SelectedValue) *************** *** 757,761 **** /// <summary> ! /// Raises a PostBack event of a control during a CallBack. /// </summary> /// <param name="eventTarget"></param> --- 757,761 ---- /// <summary> ! /// Raises a PostBack event of a control during an AjaxCall. /// </summary> /// <param name="eventTarget"></param> *************** *** 802,806 **** /// <summary> ! /// Used to store and retrieve the html rendering of the page during a callback /// </summary> private class PageFilter : Stream --- 802,806 ---- /// <summary> ! /// Used to store and retrieve the html rendering of the page during an AjaxCall /// </summary> private class PageFilter : Stream *************** *** 865,869 **** string elmID = matchDragElm.Groups["DragElmId"].Value; wpmScript.AppendLine(string.Format("if (document.getElementById('{0}') == null)", elmID)); ! wpmScript.AppendLine(string.Format(" AJAXCbo.AddElementScript('{0}','span','__DragHolder',{1},'null');", formID, CallBackHelper.EncodeString(matchDragElm.Value))); } --- 865,869 ---- string elmID = matchDragElm.Groups["DragElmId"].Value; wpmScript.AppendLine(string.Format("if (document.getElementById('{0}') == null)", elmID)); ! wpmScript.AppendLine(string.Format(" AJAXCbo.AddElementScript('{0}','span','__DragHolder',{1},'null');", formID, AjaxCallHelper.EncodeString(matchDragElm.Value))); } *************** *** 953,961 **** public override void Write(byte[] buffer, int offset, int count) { ! if ( CallBackHelper.IsCallBack ) { _memStream.Write (buffer, offset, count); ! if ( MagicAjaxModule.Instance.CompletedCallBack ) _responseStream.Write (buffer, offset, count); } --- 953,961 ---- public override void Write(byte[] buffer, int offset, int count) { ! if ( AjaxCallHelper.IsAjaxCall ) { _memStream.Write (buffer, offset, count); ! if ( MagicAjaxModule.Instance.CompletedAjaxCall ) _responseStream.Write (buffer, offset, count); } |