开发者

ascx'es javascriptscript

开发者 https://www.devze.com 2023-02-08 22:04 出处:网络
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.I

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"));
0

精彩评论

暂无评论...
验证码 换一张
取 消