ASP.NET Client Callback Manager Example

ASPX code:
[sourcecode language=”html”]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallBackExample.aspx.cs" Inherits="ClientCallBackExample" %>

Untitled Page



Code Behind:

[sourcecode language=”C#”]

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ClientCallBackExample : System.Web.UI.Page, ICallbackEventHandler
string arg;
protected void Page_Load(object sender, EventArgs e)
string cbref = Page.ClientScript.GetCallbackEventReference(this, “document.getElementById (‘txtZip’).value”,
“__onCallbackCompleted”, “null”, true);

// Wire the callback event reference to the Autofill button with
// an onclick attribute (and add “return false” to event reference
// to prevent a postback from occurring)
Button1.Attributes.Add(“onclick”, cbref + “; return false;”);

// Server-side callback event handler
public void RaiseCallbackEvent (string arg)
this.arg = arg;

public string GetCallbackResult()
if (arg.StartsWith (“378”))
return “Oak Ridge”;
else if (arg.StartsWith (“379”))
return “Knoxville”;
return “Unknown”;