WebDevGuy2 WebDevGuy2 - 1 year ago 52
Vb.net Question

How to put linebreaks on dynamically generated javascript code

Working on ASP.net website. In my webpage I'm dynamically writing some javascript in the code-behind code. How can I put linebreaks at certain points so that if I do a 'view source' of the page it is more readable? Right now all the dynamic js code is one one line.

I've tried appending

but that doesn't seem to work.



<br /> is html element which will not help you at this point. you can use Environment.NewLine to add these line-breaks: example code will be like the following:

StringBuilder strBuilderJS = new StringBuilder(); 
strBuilderJS.Append("<script language='javascript' type='text/javascript'>" + Environment.NewLine + 
                    "$(WireEvents_" + this.ID + ");" + Environment.NewLine +
                    "function WireEvents_" + this.ID + "(){" + Environment.NewLine +
                    "    alert('stuff');");
strBuilderJS.Append(Environment.NewLine + "}</script>");