ascx'es javascriptscript
I want my asp.net .ascx user control to use some javascript. How to do it properly? I am not sure what I sho开发者_如何学编程uld do? Should I use the scriptmanager object?
It depends on the situation. It's perfectly reasonable just to drop the script into your ascx files. This is what I do with simple scripts that don't have any sort of dynamic components. Also good for client-side validatation functions referenced by CustomValidator objects.
For complex scripts it's nice to separate them into their own .js files and link them or add dynamically.
Drop a script manager on the master page and then:
ScriptManager sm = (ScriptManager)master.ScriptManager1;
sm.Scripts.Add(new ScriptReference("~/Scripts/banners.js"));
精彩评论