How to use javascript in .ascx pages

我们两清 提交于 2019-12-21 12:32:31

问题


How to use javascript in .ascx pages


回答1:


You can add script tags to the markup:

<script type="text/javascript">
   // place your javascript here
</script>


<script type="text/javascript" href="path to js file" />

Or use ScriptManager in the code behind so you don't include the same file/js section multiple times if you use multiple controls in a page.

You can find out more about ScriptManager here (overview, including usage scenarios).




回答2:


I'm assuming that you included the JavaScript code within script tags in the user control page.

I'm also assuming that you are calling a function from one of the controls within the user control

Another assumption I'm making is that your user control is hidden at the loading time.

If the user control is in an UpdatePanel and/or its Visible attribute is set to false by default, you will get "Object expected" error because simply your script is not loaded when the page loads and the function you are calling is non-existent.

Workaround for this is to use style="display:none" instead of Visible="false" for your user control in the main page.



来源:https://stackoverflow.com/questions/3785816/how-to-use-javascript-in-ascx-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!