Saturday, March 24, 2012

Call function from the custom extender

var sbFunc =new Sys.StringBuilder(this._callbackFunction);

sbFunc.append(

"('");

sbFunc.append(

this.get_element().id);

sbFunc.append(

"','");

sbFunc.append(foo[foo.length-1]);

sbFunc.append(

"','");

sbFunc.append(

this.get_serviceParameter());

sbFunc.append(

"')");

sbFunc.append(

";");

window.setTimeout(sbFunc.toString(), 0);

This code works fine until first postback. After, it still call function, but function really never get called. Function is located on the bottom of aspx file (Default.aspx). Why is it happens so? Maybe I put my custom function in a wrong place? I will appreciate any help.

Where is this code? Inside a custom JavaScript control?

When you say the "first postback", do you mean an async postback via an UpdatePanel?

Could you maybe share the rest of the page with us so we can see where everything is?


Steve Marx:

Where is this code? Inside a custom JavaScript control?

When you say the "first postback", do you mean an async postback via an UpdatePanel?

Could you maybe share the rest of the page with us so we can see where everything is?

Sorry, description was too short. I have custom extender. I want to be able call function that's inside aspx page on which I drop that extender. I wrote a piece of code you can see above. window.setTimeout(sbFunc.toString(), 0); That piece of code really works fine.

For instance ifthis._callbackFunction='__callbackFunc' and I have Default.aspx file:

<asp:UpdatePanelrunat="server"ID="UpdatePanel1"ChildrenAsTriggers="false"UpdateMode="Conditional">

<ContentTemplate>

Customer:

<br/><uc1:AutoTextID="atCustomer"runat="server"Width="230"CompletionInterval="2000"CompletionSetCount="10"EnableTheming="false"EnableViewState="true"MinimumPrefixLength="1"ServiceMethod="getListNames"ServicePath="http://olexiy.esconline.cc/test2/WebService.asmx"/>

...

</ContentTemplate></asp:UpdatePanel>

...

<script type="text/javascript">

function __callbackFunc(arg0, arg1, arg2) {

alert('hello world!');

}

I can actually see this message box "hello world" up until some async postback will happen in UpdatePanel1 ('caused by some other component). Afterwards I don't see message box "hello world" anymore.

</script>


Sorry for the slow reply... I still don't how you're injecting the JavaScript you want to run.

My best guess is you're using Page.Register* instead of ScriptManager.Register*... if so, make sure you're using the ScriptManager method.


Actually I use neither one. If I try to register java script with callback function in ScriptManager then script does not receive call at all, meaning that message box is not coming up.

No comments:

Post a Comment