Ajax discussion/misconceptions — Callback hmmmm…

Ajax Ajax Ajax … every web developer job required ajax skills hmmmm what is ajax i believe ajax lets u make feel of you web application as desktop application (where no postback happens) but actually it could just make up that feel, actually postback happens but re rendering and re painting of that web page could be partial.

there i found some misconceptions about page life cycle in case of MS Ajax which i would like to share

  1. All Page’s events fire🙂
  2. Update panel control’s events also get fired (Init, Load, Prerender, Unload)
  3. Controls’ in Update Panel events also get fired after Page_Load event

What ajax do actually call server side code from client side code, different ajax providers use different technologies some use web services and create middle layer and access that web service through javascript code and web service call server activities and response.

what if you want to call server side method from javascript and don’t wanna to postback happen what would u use .hmmmm… use ajax but ajax cause postback thennnnn hmmmmm let me suggest you async CALLBACK techniques. Recently i used it and call server side method which perform sql server tasks and response asynchoronously .. no postback happens not at backend and not at all at front end😀

steps were quite simple in my case c# as example for server side code:

  1. implement server side (c#) class by System.Web.UI.ICallbackEventHandler
  2. public void RaiseCallbackEvent(String eventArgument) { to do code …}
  3. public string GetCallbackResult() { to do code … }
  4. in Page_Load or Page_Init event                                                                   ClientScriptManager cm = Page.ClientScript;
    String cbReference = cm.GetCallbackEventReference(this, “arg”, “ReceiveServerData”, “”);
    String callbackScript = “function CallServer(arg, context) {” + cbReference + “; }”;
    cm.RegisterClientScriptBlock(this.GetType(),”CallServer”, callbackScript, true);
  5. <script language=”javascript” type=”text/javascript”>
    function ReceiveServerData(arg, context)
    {
    alert(‘Processed callback.’);
    }
  6. function CallSrv()
    {
    CallServer(“adnan”, “”);
    }</script>
  7. finally pray it works😀😛😉 hahaha no it will definitely work!

step 1 is simple you just need to implement your page class by ICallbackeventhandler interface then in step 2 you can write your server side code in it then by step 3 event you can write code of response either successful or not or anything u want as callback is async then in step 4 you just need to register your methods then in step 5 client side code it runs in response and at 7 step you will call and pass parameter to server side RaiseCallbackEvent event …………………… game over you did it ….conclusively, ajax makes application efficient but enough dependent upon highly javascript compatible browser and somehow brings some loops holes as well😀 which no body bother coz every1 is looking for look & feel anyhow ajax gave new face to web development which i appreciate and comes in web 2.0 technologies which somehow made web as web operating system🙂 impressive anyhow i wont go in detail of web 2.0 and the details for why i call web as web operating system.

3 responses to “Ajax discussion/misconceptions — Callback hmmmm…

  1. Pingback: client server hell :) RegisterStartupScript || RegisterClientScriptBlock && some tips « Muhammad Adnan

  2. Pingback: client server hell - Muhammad Adnan

  3. Hi everyone i am new to this. Just thought that i would say hello to everyone! dont really know
    what else to say.I love texting, nothing else to say so bye

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s