Tag Archives: ATLAS

UpdatePanel and Rendered (Inline) Javascript

It seems that the UpdatePanel essentially replaces the InnerHTML of  a DIV with the delta returned from the server. If you try this yourself you will notice that any javascript elements in the html are not fired.

All javascript registered on the server-side (if you are using .NET) with the ScriptManager is put into a separate section of the returned delta. The atlas runtime obviously then loads these scripts into the document manually.

What if the returned HTML has Javascript tags already rendered in it? Nothing. 😦
Such was our predicament and we had no control over the HTML that would be returned to the UpdatePanel (ReportViewer Control). Could we manually load the javascript ourselves when the UpdatePanel returns the payload? As it turns, we could.

You can create script elements on the fly and they get evaluated as you do. Atlas has the ScriptLoader object that will do it for you if your JavaScript is an external reference. Tweaking this idea we got a solution that found all the new Script elements and added them to the document.

The code is below; the scriptLoader was taken from this post.
The main thing to know is that a script element has a text property that can be modified.
The atlas scriptloader sets the src property whilst the innerHTML and innerText properties are readonly.

Continue reading

Tagged , , ,