I am trying to have a method in my code behind at runtime add a function at runtime. I can dynamically add elements to my document with no problem. So I tried the same strategy for adding a script block.
Here's what I have tried thus far with no luck. It can create the script block but when I try to add the function. The only thing I can gather is that since the page is loading, it can't add the JS method. I am trying to add this before the page is loaded. So I figured I would be able to add script. If I can't add a function, I would like to at least feed it some javascript in my code behind to invoke at runtime.
Here is how I try to dynamically add the script block... which throw a runtime error on the SetProperty() method.
HtmlElement script = HtmlPage.Document.CreateElement("script");
script.SetAttribute("type", "text/javascript");
script.SetProperty("innerHTML", "function testing() { alert('hello world'); }");
HtmlPage.Document.Body.AppendChild(script);
Then to invoke an EXISTING function on the document this works...
HtmlPage.Window.Invoke("testing2");
If I can't dynamically add a script block could I somehow invoke some javascript from my code behind?
Thanks!!!