I am writing an asp.net website (in fact, the DotNetNuke module) using C #. Due to the code, I am trying to create a <script> tag where I set the required js variable and then add it to the HMTL <head> . Js var is a (literal) array of relative URLs for image files. Because the array contains strings, each element must be enclosed in quotation marks.
The problem is that the line between <script> and </script> automatically placed in HtmlEncoded, so the quotation marks around each element of the array are replaced with " . This happens when an HtmlGenericControl displayed. Could DotNetNuke be the culprit? Can anyone suggest a workaround?
My current code (works from the Page_Load handler in my control):
HtmlGenericControl PreviewDataScriptTag = new HtmlGenericControl("script"); PreviewDataScriptTag.Attributes.Add("type", "text/javascript"); StringBuilder PreviewDataScriptCode = new StringBuilder(); PreviewDataScriptCode.Append("var preview_imgs = ["); string pathPrefix = @""""; string pathSuffix = @""","; foreach (string path in this.DocPreviewImages) { PreviewDataScriptCode.Append(pathPrefix + PreviewUrlBase + Path.GetFileName(path) + pathSuffix); }
source share