views:

1299

answers:

4

I have been rather successful in promoting JQuery within my organization. No small feat on it's own. However, one of the ideas being kicked around here to make it part of our app is to create an ASP.net server side control. (We are going to be sticking with WebForms for the foreseeable future.)

I'm not too wild about this approach as it seems like overkill when a couple of script tags will do the job. We found an article on the web, and the amount of code involved really doesn't seem to justify itself. However, I do hear that there is some benefit in the script caching or generating that happens with the server controls.

My questions:

  • Has anyone else written an ASP.net server control to serve up the JQuery js code?
  • Does anyone else think that this is a crazy idea to just avoid writing JQuery or Javascript code?
+4  A: 

I know Microsoft (along with Nokia) is "mainstreaming" jQuery and will be integrating it with future versions of Visual Studio. You may want to explore how they'll be officially using it so you can tailor your setup now, and hopefully ease your transition to "official MS jQuery" down the road.

theraccoonbear
+2  A: 

I agree with you. It is not worth the time to create and overhead to create a control to make to add a JQuery script location.

A better solution would be to have 1 .js file that has all the links required to load on the page. That could eliminate allot of .js links, if that is the issue with the team.

The only time I would excuse creating a custom control to just link JavaScript would be for whatever reason you did not want to copy the JavaScript to the server and want to be embed it into the .dll. However you will not stop people from seeing the JavaScript on the page because if you embed the files in the .dll you must register them in the header as the full script file.

David Basarab
A: 

I found Scott Hanselman's blog post with a sample app that has ASP.net AJAX + JQuery. It's a simple app, but it includes all the javascript with script tags. I don't see any advisement to use a server control to serve up the scripts.

casademora
+1  A: 

One reason for using a server control for injecting the JavaScript reference is that it is easier to control which JavaScript files get added to a page. Imagine a scenario where you use jQuery core, plus jQuery UI and a handful of other plugins. Depending on how you coded this control, you could allow a developer to easily choose which features were needed for a specific page without worrying about the specific scripts needed. This approach would allow you lots of flexibility for segmenting your application: for example the server control might be used by a master pages, a child page, user controls or another server control. If the master page registered a requirement for one jQuery library, but the child page or one of the user controls requires additional libraries, then having a unified API makes this simple. Personally, I believe this is best handled by a helper library rather than a server control.

The bottom line is how much you want each developer re-inventing the wheel or using a common, simple to use API which enforces uniformity across your apps.

Joe Brinkman
I can see this scenario, but is it worth writing more code to manage other code? I'm not a big fan of this idea, so I'm trying to find some merit in it somewhere.
casademora