Friday, June 11, 2010

ICallbackEventHandler in .net for Partial Postback like Ajax



Code follows :

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

public partial class zRMX_CallBackData : System.Web.UI.Page , ICallbackEventHandler
{
private string _callbackResult = null;

protected void Page_Load(object sender, EventArgs e)
{
string cbreference = Page.ClientScript.GetCallbackEventReference(this, "arg", " GetRandomNumberFormServer", "context");

string cbscript = "function UseCallback(arg , context ) " + "{" + cbreference + "}";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallback", cbscript, true);
}

public void RaiseCallbackEvent(string eventArg)
{

Random rnd = new Random();
_callbackResult = ss.Text + "/" + rnd.Next().ToString();
}

public String GetCallbackResult()
{

return _callbackResult;

}

}


Code For javascript :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CallBackData.aspx.cs" EnableViewState="false" Inherits="zRMX_CallBackData" %>





Untitled Page











No comments: