开发者

How to use javascript in .ascx pages

开发者 https://www.devze.com 2023-01-17 05:06 出处:网络
How to use javascript in .ascx pa开发者_运维问答gesYou can add script tags to the markup: <script type=\"text/javascript\">

How to use javascript in .ascx pa开发者_运维问答ges


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).


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.

0

精彩评论

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