1

I have a button on my page that does an Ajax callback with an onclick javascript method. I want to re-register ALL the Javascripts on the page after the ajax is completed. I have a common init method that I call on ajaxComplete with some functions called after ajax completion.

However, there are several javascripts, and in different files. Is it possible to get all the javascript files (based on the file names on the server) and re-register them onAjax complete?

I am using C#/.NET (.NET ajax) and if there's a way to register the files via code behind (on ajax complete).

Currently I have a javascript method that is called on ajax completion, is there any way to place this inside code-behind to re-register the javascripts?

Sumurai8
  • 20,333
  • 11
  • 66
  • 100
Loser Coder
  • 2,338
  • 8
  • 42
  • 66
  • I think if you can't place all the js that you want to rerun in a single function call that you might be better off with performing a page reload rather than using ajax. – scrappedcola Oct 14 '11 at 16:27
  • you want to "re-register"? or do you mean "re-execute". I'm guessing that your ajax returns some html that you want to (re)bind event handlers to perhaps? – Al W Oct 14 '11 at 17:10
  • reBind event handlers - I am able to do this by regenerating the innerHTML to add the events again (i.e in the html returned by ajax) – Loser Coder Oct 24 '11 at 19:10

1 Answers1

0

Personally, I would load all the javascript I needed right off the bat. This alleviates complexity and makes small nuisances like naming conflicts easier to troubleshoot.

However -- if you still want to go with the dynamic loading route, then all you need to do is create a js function that dynamically loads the files you need (multiple ways to accomplish this) and register that function with the scriptmanager on the page for subsequent calling. If you're not keen on using the scriptmanager, then you'll need to call the aforementioned script-loading function you created from within your onAjaxComplete function.

For thoroughness, I should add that there are some really good dynamic script loading libraries available.

Community
  • 1
  • 1
Daniel Szabo
  • 7,181
  • 6
  • 48
  • 65