29.5.07

jQuery Manager for .Net

I released the early version of my jQuery Script Manager today on CodePlex.
Its an idea that I have had for the past couple of days in an attempt to make using jQuery and ASP.Net work nicely. I've been using JavaScript lately with SharePoint (WSS v3 & MOSS) and I've been unhappy with how injected JavaScript can get really messy. This project is an attempt to make it better.

What is jQuery you ask?

So here is how its currently used:

1) Add the jQuery Script Manager to the page

<%@ Register Assembly="jQuery.ScriptManager, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=null
" Namespace="jQuery.ScriptManager" TagPrefix="jQuery" %>

...

<jQuery:jQueryManager id="jQueryM" runat="server">
</jQueryManager>


2) register any JavaScripts functions that need to run on document.load

<jQuery:jQueryManager id="jQueryM" runat="server">
<ReadyFunctions>
<jQuery:RegisterReadyFunction FunctionName="TestFunction" />
</ReadyFunctions>
</jQueryManager>


3) Create the JavaScript function

function TestFunction(){
alert('The page has loaded!');
}


The JavaScript function "TestFunction" will be called when the page loads by placing it in jQuery's $(document).ready function.

4 comments:

Morne said...

I tried to use this script manager to add jQuery to a user control with no luck. I just cant get it to work.

I specified my FunctionName that should start on $(documnet).ready() and I can see that the manager has writen that part to my page, but there is nothing else. Firebug just gives me an error saying that $ is not defined.

I have now resorted to Page.ClientScript.RegisterClientScriptInclude method to register the jQuery file and then added the the jQuery script on the html page of the control and that seems to work fine.

The Scriptmanager seems like a really cool idea but maybe some extra documentation for spoonfeeders like me would help.

prodactor said...

Hi morne,
I've made some updates to the script manager - hopefully now you will have more luck.
The main problem was finding the right Page event to register the scripts. When it happens out of order the jquery script got added after the custom scripts and so the $ extension wasn't registered properly.

I agree that some more documentation would be helpful - ill see how I go at making some.

VijayS said...

Great idea! I can't wait to try this out.

velocity boy said...

Hey,

I've been using jQuery with SharePoint since 2005, and last week I open sourced the way that we dynamically insert our JavaScript fragments into the SharePoint pages we're interested in.

You can find it here:
http://www.codeplex.com/ShUIE/

It gives you a nice central location to store your customisations, and central management of where the customisations will appear :)