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 th开发者_如何学运维e .ascx page.
<script type="text/javascript">
</script>
However, the function UserControlNameInit() does not run when the page loads. It is showing in the page source. I can still call this function through FireBug console by manually typing the name of the function.
I did the same way with other user controls, and it works. Just 1-3 user controls are not working...
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. 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.
精彩评论