Skip to content
Advertisement

ASP.Net Webform: Add HTML and javascript dynamically

I need a ASP.net application which is only kind of “pageDisplayer” from content which is coming from an API. So I choose ASP.net Webform and tried the following:

JavaScript
JavaScript

The html content and the script are loaded correct but I cannot access DOM elements in the javascript. The javascript looks like that

JavaScript

No I get the error “form is null”. For me it looks like the javascript is executed before the DOM is ready. But how can I change this to make it work like expected?

Advertisement

Answer

Try putting the JS (literal) at the bottom of the page, before the closing body tag. That way, the HTML will be loaded before the JS tries to find elements.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement