Click here to Skip to main content
15,886,199 members
Articles / Web Development / ASP.NET

Client Callbacks in ASP.NET 2.0

Rate me:
Please Sign up or sign in to vote.
4.83/5 (20 votes)
24 May 2006CPOL5 min read 133.6K   573   72  
Explains the concept of client callbacks in ASP.NET 2.0.
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page, ICallbackEventHandler   
{
    string callbackResult;
protected void Page_Load(object sender, EventArgs e)
{
    string cbref = Page.ClientScript.GetCallbackEventReference(this, "arg", "JSCallback", "context");
    //Response.Write(cbref);
    string cbScr = string.Format("function UseCallBack(arg, context) {{ {0}; }} ", cbref);
  //  Response.Write("<BR>" + cbScr);

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallBack", cbScr, true);
}

    #region ICallbackEventHandler Members

    public string GetCallbackResult()
    {
        return callbackResult;
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        // perform some real operation
        callbackResult = "DotNET Rocks!";
    }

    #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 Code Project Open License (CPOL)


Written By
Web Developer
United Arab Emirates United Arab Emirates
Iam Nasir Ali Khan, working a software architect in Dubai, works primarily on Microsoft Platform, MCTS certified for windows/web/distributed/mobile/enterprise applications.
Also teaches CS courses in a university in dubai.

Comments and Discussions