Bogdan Verbenets
Bogdan Verbenets

Reputation: 26936

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 should do? Should I use the scriptmanager object?

Upvotes: 0

Views: 217

Answers (2)

Bogdan Verbenets
Bogdan Verbenets

Reputation: 26936

Drop a script manager on the master page and then:

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

Upvotes: 0

Bryan
Bryan

Reputation: 8778

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.

Upvotes: 1

Related Questions