Wednesday, March 21, 2012

Need help with RegisterClientScriptResource

I am having a huge problem withRegisterClientScriptResource - I can't seem to keep it from re-registering the same script over and over. I have a control called a Popup (a floating div) which has to inject some javascript when added to the page. The problem is, there can be several Popups on a given page, and if so, the javascript is being injected several times, once for each Popup on the page. I've done my best to word things properly, but it's just not stopping the multiple instances. Here is a sample command that is causing the problem:

ScriptManager.RegisterClientScriptResource(Page,typeof(Popup),"Framework.Bus.Resources.javascript.popup.js");

And I have also tried:

ScriptManager.RegisterClientScriptResource(this,typeof(Popup),"Framework.Bus.Resources.javascript.popup.js");

Notice that I amNOT using GetType(), which is what every article in existance seems to indicate would be causing the problem. This commandIS part of a "base class" which is always inherited from.

What am I doing wrong? Barring that, is there a way to test if the script in question is already injected, so that I can just avoid re-injecting the same script?

Just giving this a nudge because I'm in a tough situation and can't seem to figure it out. I really need some assistance, if anyone has info about this. - Thanks
Daily bump - any ideas?

I have the same problem. Now I have my page inherits IScriptControl and use GetScriptReference to register scripts.

btw, for it to work you will have to call ScriptManager.registerScriptControl in render override.


Rushui

No comments:

Post a Comment