Monday, March 26, 2012

Duplicate Script Reference

I am trying to create a WebControl dll. There is a common.js file in the dll. It is shared bewteen all WebControls.

If I simply add the script reference using
ScriptManager.Scripts.Add( ...) or implementingGetScriptReferences function of IScriptControl. Duplicate script reference will be created when user add multiple web controls.

It is a problem because a ajax javascript class cannot be registered twice.

If I use ScriptManager.RegisterClientScriptInclude, the script will be unique but it is inserted before ajax javascript liberary.

It seems that I have to do something special to make this work. anyone has suggestions or has experienced the same issue??

thanks

Rushui

Look up the example under ajax.asp.net/docs for the IScriptControl interface. If you implement the interface using their example as a template you shouldn't have issues; I'm not sure what they're doing under the hood, but the GetScriptReferences method specified is being called in some way that helps avoid conflicts.

Upon further investigation, it seems that duplicate script reference of a web control dll can be avoided by implementing GetScriptReference function of IScriptControl interface. The Scripts collection of ScriptManager however doesnot check for duplicates.

My situation is a bit strange since I am trying to share a common js lib between the page and the web control dll. Guess I just have to avoid doing that.

Thanks

Rushui

No comments:

Post a Comment