how to manage jQuery and included jQuery plugins with asp.net form architecture
we are building a site using asp.net form with a lot of usercontrols that are written by different developers. One of the questions we are trying to solve is to manage included jQuery library and its plugins.
we are currently using google cdn for jQuery, jquery ui; jquery plugins are hosted locally.
we are trying to find a way to allow u开发者_StackOverflow中文版sercontrol to include its own library from google or locally if they are not already loaded.
Research ClientScriptManager class
http://blogs.syrinx.com/blogs/dotnet/archive/2009/01/19/how-to-use-the-client-script-manager.aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx
If you are willing to work with code in active development (that is... beta :), I have a project that is nearly ready for prime time that deals with this, as well as a lot of other things related to client scripting in asp.net UserControls and server controls (e.g., naming container issues, asp.net event interaction, and so on). The basic use is pretty simple, e.g. you can probably figure out what this does. This would be dropped into a UserControl, but all the same can be effected from code (e.g. for a server control).
<JTC:ScriptContext runat="server" ID="ControlScriptContext" StartupType="Jquery">
<Scripts>
<JTC:ScriptReference Name="jquery" />
<JTC:ScriptReference Name="jqplot" />
<JTC:JavascriptInclude Path="~/scripts/Decorator.js" />
<JTC:ScriptFunction Function="controlStartup" Execution="Startup" />
<JTC:ScriptFunction Function="pieStartup" Execution="AsyncPostBegin" />
</Scripts>
<ServerReferences>
<JTC:ObjectReference ControlID="ModalPopup" />
<JTC:PropertyReference PropertyName="PieChartData" />
</ServerReferences>
</JTC:ScriptContext>
ScriptReferences
are established globally using a construct identical to Microsoft's ScriptManager.ScriptResourceMapping
and supports cdn, as well as css and one-to-many references to scripts, unlike the MS version. It also provides methods to simplify using embedded resources so you can create truly self-contained server controls.
The project page & source is here and I would welcome any input or involvement from people interested in it.
精彩评论