简体   繁体   English

ASP.Net用户控件Java脚本功能未运行

[英]ASP.Net User Control Java Script function does not run

I have the function put here like below: 我的功能如下所示:

$(document).ready(function () {
     UserControlNameInit();
});

The script are put in the following and the block is in the .ascx page. 该脚本位于下面,该块位于.ascx页中。

<script type="text/javascript"> </script>

However, the function UserControlNameInit() does not run when the page loads. 但是,该函数UserControlNameInit()在页面加载时不会运行。 It is showing in the page source. 它显示在页面源中。 I can still call this function through FireBug console by manually typing the name of the function. 我仍然可以通过手动输入功能名称,通过FireBug控制台调用此功能。

I did the same way with other user controls, and it works. 我对其他用户控件进行了相同的操作,并且可以正常工作。 Just 1-3 user controls are not working... 只有1-3个用户控件不起作用...

Any possible reason for this? 有任何可能的原因吗? Thanks! 谢谢!

I think I found the problem. 我想我找到了问题。 Thanks to IE 9 Beta's developer tool, which actually allow me to debug it and I saw script exception when the page loads and the problem is because of the newly added user control render html in correctly and block the functions call in the old user control. 多亏了IE 9 Beta的开发人员工具,该工具实际上允许我对其进行调试,并且在页面加载时看到脚本异常,问题是由于新添加的用户控件正确地呈现了html并阻止了旧用户控件中的函数调用。 After I comment out the other user controls in the pages, the problem is gone. 在我注释掉页面中的其他用户控件后,问题消失了。 Now I need to figure out which control actually cause the problem. 现在,我需要找出哪个控件真正导致了问题。

Update: I think I found the right answer for this problem: I have initialization code written as below: 更新:我想我找到了解决这个问题的正确答案:我有如下编写的初始化代码:

$(document).ready()
{
     UserControlNameInit();
}

Which blocks the call in the other user control which is written as this: 在另一个用户控件中阻止了该调用,其编写方式如下:

$(document).ready(function(){ 
    UserControlNameInit(); 
});

Although I don't know the difference between these too. 尽管我也不知道两者之间的区别。 But the later code seems to cause no problem to other user controls. 但是后面的代码似乎对其他用户控件没有问题。

Thank you for all the attention and help. 感谢您的关注和帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM