To include JavaScript in a tag, use the AddJavaScript method inside the DisplayTag method.
HTMLScriptCollection scriptCollection = new HTMLScriptCollection(); HTMLScript script = new HTMLScript("text/javascript"); scriptCollection.AddInnerHTMLElement(script); script.AddInnerHTMLString("function myTest() { alert('test'); }"); AddJavascript(scriptCollection);
/** * Adds the PTIncluder object to the client. This object is used for * retrieving JSComponent client classes from a page. */ public HTMLScriptCollection DisplaySharedJavascript() { HTMLScriptCollection result = new HTMLScriptCollection(); HTMLScript script = new HTMLScript("text/javascript"); result.AddInnerHTMLElement(script); script.SetSrc("/myjsfile.js"); return result; }If there are errors in the tag and the JavaScript cannot be displayed properly, the tag should throw an XPException with an error message, and the tag framework will log the error and add the message and stack trace to the HTML as an HTML comment. The message contents will be HTML encoded before being added to the comment.