ascx'es javascriptscript

225 Views Asked by At

I want my asp.net .ascx user control to use some javascript. How to do it properly? I am not sure what I should do? Should I use the scriptmanager object?

2

There are 2 best solutions below

0
On BEST ANSWER

Drop a script manager on the master page and then:

ScriptManager sm = (ScriptManager)master.ScriptManager1;
sm.Scripts.Add(new ScriptReference("~/Scripts/banners.js"));
0
On

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.