I developed a custom control (not a user control) that uses some jQuery scripts.
I included the script control as a built-in resource in the assembly and registered it on the page in the OnPreRender event, for example:
protected override void OnPreRender(EventArgs e)
{
string controlScript = "Namespace.MyScript.js";
ClientScriptManager csm = this.Page.ClientScript;
csm.RegisterClientScriptResource(typeof(ResourceFinder), controlScript );
base.OnPreRender(e);
}
This control works when deployed to a project with an existing jQuery library, but what if the jQuery library is not available. How can I check if the library is already in the project, and if not, then build it into the assembly and pull it out. I thought something like:
protected override void OnPreRender(EventArgs e)
{
ClientScriptManager csm = this.Page.ClientScript;
if (csm.IsClientScriptResourceRegistered("jQuery"))
{
string jQueryLib = "Namespace.jquery-1.7.2.min.js";
csm.RegisterClientScriptResource(typeof(ResourceFinder), jQueryLib);
}
string controlScript = "Namespace.MyScript.js";
csm.RegisterClientScriptResource(typeof(ResourceFinder), controlScript );
base.OnPreRender(e);
}
I know that in any case, I could embed the jQuery library in the assembly, but if jQuery was already in the project, I would get a page with two libray calls, for example:
<script type="text/javascript" src="/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/WebResource.axd?d=AP7y...r0bHQl"></script>
<script type="text/javascript" src="/WebResource.axd?d=uTGR...ur15b"></script>
... this is what I am trying to avoid.
?