Click here to Skip to main content
15,897,163 members
Articles / Web Development / HTML

Magic AJAX: Applying AJAX to your existing Web Pages

Rate me:
Please Sign up or sign in to vote.
4.82/5 (72 votes)
28 May 2007MIT12 min read 984.4K   2.7K   251  
How to apply AJAX technologies to your web pages without replacing ASP.NET controls and/or writing JavaScript code.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

namespace MagicAjax.UI.Controls
{
	/// <summary>
	/// Base class for controls that capture the client events of their inner controls.
	/// </summary>
	[Designer("MagicAjax.UI.Design.BaseClientEventWrapperDesigner, MagicAjax"),
		ParseChildrenAttribute(false),
		PersistChildren(true)]
	public abstract class BaseClientEventWrapper : ClientEventControl
	{
		protected abstract void AttachClientEvents (HtmlTextWriter writer);

		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			base.AddAttributesToRender (writer);
			AttachClientEvents(writer);
		}

		protected virtual void AttachEvent (string eventName, string getArgumentScript, HtmlTextWriter writer)
		{
			if (getArgumentScript == null)
				writer.AddAttribute (eventName, String.Format("__doPostBack('{0}',event.type+';');", UniqueID));
			else
				writer.AddAttribute (eventName, String.Format("arg={0};__doPostBack('{1}',event.type+';'+arg);", getArgumentScript, UniqueID));
		}
		protected void AttachEvent (string eventName, HtmlTextWriter writer)
		{
			AttachEvent (eventName, null, writer);
		}
	}
}

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


Written By
Web Developer
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions