How to Perform Async Post Back via Javascript

if you are advanced in asp.net skip to Solution.

Beginners Tutorial

When you have updatePanel you have to register via Template , Trigger->AsyncPostBackTrigger, or Through Programatically on Page_load ex:

scriptManager.RegisterAsyncPostBackControl(mycontrol);

 I've got a case which i've got JQuery autocomplete , i've got a textbox Inside UpdatePane(runat server, and have an event of TextChanged On Server)

After user click auto complete i need to Refresh the UpdatePanel. while the autocomplete is not triggering the ontextchanged event. Yes, i heard you saying this and that ..

But there is a neat way to Refresh the UpdatePanel through javascript, that is by using The solution below function.so that you have full control on updatepanel trigger.

Solution

we do know that __dopostback require  us to provide clientid, and targetEventName which we are going to call

There is call back architecture but that is not the case.

 

how about when you have update panel, scriptmanager, and want to manualy force postback via javascript 

we must register this event on the Page Request Manager.

 http://bloggingabout.net/blogs/mveken/archive/2008/01/02/performing-async-postback-from-javascript.aspx

 

 function doPostBackAsync(eventName, eventArgs) {
                var prm = Sys.WebForms.PageRequestManager.getInstance();

                if (!Array.contains(prm._asyncPostBackControlIDs, eventName)) {
                    prm._asyncPostBackControlIDs.push(eventName);
                }

                if (!Array.contains(prm._asyncPostBackControlClientIDs, eventName)) {
                    prm._asyncPostBackControlClientIDs.push(eventName);
                }

                __doPostBack(eventName, eventArgs);
            }

you can use it like

doPostBackAsync('<%= txtsearchauto.ClientID %>', 'OnTextChanged');

it will make async post back,  call page load then the event we specify

Rocks!

Share this post: | | | |
Published Sunday, August 23, 2009 12:16 AM by cipto
Filed under:

Comments

# re: How to Perform Async Post Back via Javascript

Monday, August 24, 2009 8:58 AM by Irman

Boss kita ini mau belajar toh ya di jelaskan dulu maksudnya apa gito loh posting blognya.

kek di codeproject ada pendahuluan isi dan kesimpulan. biar ane-ane yang awan ngerti.

Thanks

# re: How to Perform Async Post Back via Javascript

Monday, August 24, 2009 9:46 AM by cipto

Oh gitu.. tapi ya emang ini buat yang agak advanced.. kalo uda ketemu kasusnya baru kepake.

bentar mungkin tar aku update lagi biar lbh jelas