Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » Ajax » General » Downloads
 
Add your own
alternative version

Magic AJAX: Applying AJAX to your existing Web Pages

, 28 May 2007
How to apply AJAX technologies to your web pages without replacing ASP.NET controls and/or writing JavaScript code.
magicajax-030-net11.zip
magicajax
Examples
ExampleSite (.NET 2.0 only)
Web.sitemap
webparts
images
first.GIF
last.GIF
next.gif
pow_by_aspnet2.0.gif
prev.GIF
examples
App_Data
App_Code
Docs
Core
script
bin
MagicAjax.dll
magicajax-030-net20.zip
MagicAjax.dll
Web.sitemap
first.GIF
last.GIF
next.gif
pow_by_aspnet2.0.gif
prev.GIF
magicajax-030-source.zip
Web.sitemap
CVS
Root
Repository
Entries.Old
Entries
Entries.Extra.Old
Entries.Extra
first.GIF
last.GIF
next.gif
pow_by_aspnet2.0.gif
prev.GIF
CVS
Root
Repository
Entries.Old
Entries
Entries.Extra.Old
Entries.Extra
CVS
Root
Repository
Entries.Old
Entries
Entries.Extra.Old
Entries.Extra
CVS
Root
Repository
Entries.Old
Entries
Entries.Extra.Old
Entries.Extra
CVS
Root
Repository
Entries.Old
Entries
Entries.Extra.Old
Entries.Extra
CVS
Root
Repository
Entries
Entries.Extra
Entries.Old
Entries.Extra.Old
CVS
Root
Repository
Entries.Old
Entries.Extra.Old
Entries
Entries.Extra
CVS
Root
Repository
Entries
Entries.Extra
Entries.Old
Entries.Extra.Old
MagicAjax.snk
CVS
Root
Repository
Entries.Old
Entries.Extra.Old
Entries
Entries.Extra
UI
Design
CVS
Root
Repository
Entries.Old
Entries.Extra.Old
Entries
Entries.Extra
Controls
ClientEventControls
CVS
Root
Repository
Entries.Old
Entries
Entries.Extra.Old
Entries.Extra
CVS
Root
Repository
Entries.Extra
Entries.Old
Entries
Entries.Extra.Old
CVS
Root
Repository
Entries.Old
Entries.Extra.Old
Entries
Entries.Extra
Interfaces
CVS
Root
Repository
Entries.Old
Entries.Extra.Old
Entries
Entries.Extra
Configuration
CVS
Root
Repository
Entries.Old
Entries.Extra.Old
Entries
Entries.Extra
CVS
Root
Repository
Entries
Entries.Extra
Entries.Old
Entries.Extra.Old
CVS
Root
Repository
Entries.Old
Entries.Extra.Old
Entries
Entries.Extra
magicajax.zip
AJAXTest
AJAXTest.csproj.webinfo
Global.asax
Ajax
Ajax.csproj.user
Controls
Design
script
#region LGPL License
/*
MagicAjax.NET Framework
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.Web;
using System.ComponentModel;

namespace MagicAjax.UI
{
	/// <summary>
	/// Includes the AjaxCall events and some helper properties.
	/// </summary>
	/// <remarks>
	/// Inheriting from AjaxUserControls is not required, you can implement the
	/// 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; }
		}

		/// <summary>
		/// Determines if the control is being processed during an AjaxCall.
		/// </summary>
		[Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public bool IsAjaxCall
		{
			get { return _isAjaxCall; } 
		}

		protected MagicAjaxContext MagicAjaxContext
		{
			get { return _magicAjaxContext; }
		}

		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 );
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

Argiris Kirtzidis
Web Developer
Greece Greece
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 28 May 2007
Article Copyright 2005 by Argiris Kirtzidis
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid