Wednesday, July 23, 2008

Use ICallbackEventHandler in Asp.Net 2.0

Use ICallbackEventHandler in Asp.Net 2.0

==================================



For Example, you have page Layout is like this :


































Steps to Implement ICallbackEventHanler:

-------------------------------------------------



1. First define string variable in Common section of your code behind (.cs) file.



string _CallBackString;



2. Inherit ICallbackEventHandler in your page.



public partial class Customize : System.Web.UI.Page, ICallbackEventHandler



3. Now, write this code in your Page_Load() Event



ClientScriptManager cs = Page.ClientScript;



string cbRef = cs.GetCallbackEventReference(this, "arg", "ShowPop", "context");

string cbScript = "function CallPopBack(arg, context){" + cbRef + ";}";

cs.RegisterClientScriptBlock(this.GetType(), "CallPopBack", cbScript, true);



4. Now, Write some javascript code, in your design section of your page.



function GetPop()

{

var justExample = 'Hi..All..';



CallPopBack(justExample)

}

function ShowPop(result, context)

{



var strResult = new String();

strResult = result;



alert(result);

}



4. Now, In your code behind (.cs) file, write code for your EventHandle Method.



public string GetCallbackResult()

{

return _CallBackString;

}



public void RaiseCallbackEvent(string eventArgument)

{

_CallBackString = eventArgument + " " + DateTime.Now.ToShortTimeString();

}



5. Run the page and test this page.





Hope you will like it.

No comments:

Post a Comment