views:

592

answers:

1

I have been using Anthem.NET in ASP.NET 2.0 projects for a few side projects and have a question regarding a slick piece of functionality that appears unique to this framework. I have worked with Telerik and Microsoft ASP.NET AJAX Frameworks and the ability to execute a JavaScript function from within an "ajaxified" control in a code behind page (server side) seams to be missing.

The anthem example can be found here: http://anthem.talloaksoftware.com/InvokeClientSideFunctionAfterCallBack.aspx?1

Essentially, you wrap a textbox and a button with an Ajax Update Panel (in the Anthem Framework), and then in the codebehind (or inline code) page, you can execute a javascript function after your callback has completed. But, your server side code actually specifies the javascript code that will run.

Example: The following code is executed when a button is clicked, which after performing the ajax request to the server, executes a JavaScript function that was specified server side.

Anthem.Manager.AddScriptForClientSideEval("ClientSideFunction();");

So, as long as the JavaScript function "ClientSideFunction()" exists, it will execute after the callback completes. I can immediately see how the inclusion of jQuery and utilizing this feature would make a very interesting combination. Code could still be written in the traditional postback model, but the JavaScript code could be called after the server side code is executed. This would allow server side code to "animate" the HTML objects using jQuerys built in functions.

My question is, how to duplicate this behavior using ASP.NET AJAX 3.5 built into .NET Framework 3.5? Can it be duplicated as easily as the Anthem.NET framework provides?

Anthem is not an active project anymore (on sourcefourge), so I feel it is wise to build new projects using the supported and popular ASP.NET AJAX Framework (especially with 4.0 coming), so I am looking for an equivalent solution.

+2  A: 

Really simple, you'd to have a ScriptManager on the page then server-side, when the updatepanel is updating (before the method .Update() ) just use:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "uniqueJSBlockName", "ClientSideFunction();", true);

will execute the function called ClientSideFunction(), you can hold the necessary js functions already registered on the page.

tanathos