views:

39

answers:

1

We've been using IScriptControl to tie javascript objects to our UserControls and ServerControls, and it's worked fine.

The problem is that ASP.NET seems to provide no method to tie a javascript object to a Page. Up to now, we've been putting plain functions in the global namespace, but I am developing a serious allergy to that practice.

It'd be easy enough to wrap our functions into a javascript class, and to include the javascript file on the page, but how to instantiate the object, how to reference it from callback events, and how to pass data to it from the code-behind, I haven't figured out.

Or rather, the methods we've been using up to now (hidden fields, emitted javascript strings, etc.), really bug me.

Anyone have better ideas?

A: 

Hey,

There isn't any association between the JS file and the page, unless you build it. With script controls, the common practice to store state is hidden fields (the ACT uses this approach). The only other ways to communicate with the server is through a web service call, form posted data, or by invoking a __doPostBack (but that isn't AJAX).

You can create some base architecture to link the two together. With script controls, the server renders a $create statement to pass properties and event handlers from the server to the client; data being posted back to the server is stored in hidden variables and processed on the client (with most script libraries), so script controls and ACT hide a lot of this for you, and you would have to build some of this if you wanted to automate this. It may help to study the client-server interaction to give you ideas of what to do if you wanted to customize this.

Funny, I was thinking of the same thing for my Nucleo project (a third party library of mine) on codeplex, but I haven't yet gotten around to it.

Brian
There isn't any association between the javascript and the page unless someone builds it. With ScriptControl, MS has built a structure to provide the communication for UserControls and ServerControls. It just seems odd to me that they would not have for Page, as well.
Jeff Dege