Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(document).ready in ascx page after ajax callback

I'm having a little problem with this setup here I have a list of .ascx files and they all do different tasks in terms of calculations to the controller itself. So on my .aspx page I click on an Ajax.ActionLink() and this will render that specific .ascx file based on the item I clicked. Within that .ascx are 1-3 events that will fire 2 of them are onclick events and 1 is onload. The onclick event(s) are easier to work with in terms of I can hardcode it directly in the controls event like so onclick="$("#toggleMe3").slideToggle("slow");" and the onload must run when the .ascx is loaded i was testing this in a $(document).ready(function(){}); call, this works fine in the .aspx page but as soon as I try adding it into the .aspx page it doesn't load and its ideal that this works but I have no idea why not. In fact nothing in the script tags work if I insert directly into the .ascx page they only work if hardcoded into the control's events, well some of them at least; the onload and onprerender don't fire.

like image 706
Ayo Avatar asked Oct 26 '22 05:10

Ayo


1 Answers

I had the same problem, after partial postback script specified in $(document).ready was not executed. I found solution here MSDN - PageRequestManager Class

Looks like adding a script like below fixes the issue

<script type="text/javascript">
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(myReadyFunction);
</script>
like image 156
Ghena Avatar answered Nov 15 '22 04:11

Ghena