Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version
Go to top

Implement Script Callback Framework in ASP.NET 1.x

, 2 Aug 2004
It allows calls to server events from client script code without causing the page to post back and refresh.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ScriptCallbackFramework
{
	/// <summary>
	/// Implement the in IClientCallbackEventHandler Page Control
	/// </summary>
	public class index : PageTemplate, IClientCallbackEventHandler
	{
		#region Member Vars
		protected System.Web.UI.HtmlControls.HtmlInputButton IncreaseButton;
		protected System.Web.UI.HtmlControls.HtmlInputText txtValue;
		protected ScriptCallbackFramework.AgeCalculator AgeCalculator1;
		protected System.Web.UI.HtmlControls.HtmlForm Form1;
		#endregion
		
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
		
		#region Page_Load
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				//	Callback synchronously
				IncreaseButton.Attributes["onclick"] = GetSyncCallbackEventReference
					(
						Form1,
						String.Format("document.getElementById('{0}').value", txtValue.UniqueID),
						"IncreaseValueHandler",
						String.Format("document.getElementById('{0}')", txtValue.UniqueID),
						null
					);
			}
		}
		#endregion

		#region IClientCallbackEventHandler Members

		public string RaiseClientCallbackEvent(string eventArgument)
		{
			if (eventArgument == null || eventArgument == String.Empty)
				return "1";
			return Convert.ToString(Convert.ToInt32(eventArgument) + 1);
		}
		
		#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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Elvin Cheng

Singapore Singapore
Elvin Cheng is currently living in Woodlands, Singapore. He has been developing applications with the .NET Framework, using C# and ASP.NET since October 2002. Elvin specializes in building Real-time monitoring and tracking information system for Semi-conductor manufacturing industry. During his spare time, he enjoys reading books, watching movie and gym.
Follow on   Twitter

| Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 3 Aug 2004
Article Copyright 2004 by Elvin Cheng
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid