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 Copyright
/*
Copyright (C) 2005 Argiris Kirtzidis
This script is supplied "as is" without any form of warranty. I shall not be liable for
any loss or damage to person or property as a result of using this script. Use this script
at your own risk! You are licensed to use this script free of charge for commercial or
non-commercial use providing you do not remove the copyright notice or disclaimer.
*/
#endregion

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Ajax.Controls
{
	/// <summary>
	/// Works like LinkButton but PostBack call is replaced for a CallBack call.
	/// </summary>
	/// <remarks>
	/// It is provided for convenience. Instead of putting a LinkButton inside an AjaxPanel
	/// or setting it's onclick event in order to replace the PostBack call with a CallBack
	/// call, use this control instead.
	/// </remarks>
	public class AjaxLinkButton : LinkButton
	{
		private string postBackReplacementFunction = null;

		#region Properties

		/// <summary>
		/// It determines the function that will replace PostBack. By default it uses the CallBack function.
		/// </summary>
		/// <remarks>
		/// Use this property if you want to replace postback with a custom javascript
		///  function.
		/// </remarks>
		/// <example>
		/// In your code:
		/// <code>
		/// ajaxLinkButton.PostBackReplacementFunction = "AjaxLink_Click";
		/// </code>
		/// 
		/// In your javascript script:
		/// <code>
		/// function AjaxLink_Click(linkTarget, argument)
		///	{
		///		ClearPreviousLoading();
		///	
		///		var link = document.getElementById(linkTarget.split(":").join("_"));
		///		
		///		PutCurrentLoading(link);
		///	
		///		AJAXCbo.DoPostCallBack(linkTarget, argument);
		///	}
		/// </code>
		/// </example>
		public virtual string PostBackReplacementFunction
		{
			get
			{
				return ( postBackReplacementFunction == null) ? CallBackHelper.CallBackClientFunction : postBackReplacementFunction;
			}
			set
			{
				postBackReplacementFunction = value;
			}
		}
		#endregion

		#region Protected Methods

		protected override void OnPreRender(EventArgs e)
		{
			// Register 'CallBackObject.js' script
			CallBackHelper.EnableAjaxOnPage();
			base.OnPreRender (e);
		}

		/// <summary>
		/// It replaces the "__doPostBack" client function from the rendered html.
		/// </summary>
		/// <param name="writer"></param>
		protected override void Render(HtmlTextWriter writer)
		{
			if ( !CallBackHelper.IsCallBack )
			{
				base.OnPreRender(EventArgs.Empty);
			}
			
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			HtmlTextWriter strwriter = new HtmlTextWriter(new System.IO.StringWriter(sb));
			base.Render (strwriter);

			if ( !CallBackHelper.IsCallBack )
			{
				// During normal rendering, EventTarget uses '$' for separator char,
				// but during a CallBack it uses ':'. Put ':' always so that it doesn't
				// seem like the rendered html has changed, and an unnecessary refresh
				// of the control is made.
				sb.Replace(UniqueID.Replace(':', '$'), UniqueID);
			}
			sb.Replace("__doPostBack", PostBackReplacementFunction);
			writer.Write (sb.ToString());
		}
		#endregion
	}
}

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
Web02 | 2.8.140814.1 | Last Updated 28 May 2007
Article Copyright 2005 by Argiris Kirtzidis
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid