title: How to deal with linebreaks when outputting Javascript from code behind
body: <p>I'm outputting client side function calls from code behind via</p>
  
  <pre><code>Page.ClientScript.RegisterStartupScript( this.GetType(), "supportItems", scriptCalls, true );
  </code></pre>
  
  <p>scriptCalls contains call(s) to a client side function that has several string arguments taken from database and that then displays the parameters in HTML textareas, so line breaks need to ultimately be preserved. If the DB value includes a linebreak then the linebreak gets included in the outputted client script which of course then causes a client script error.</p>
  
  <p>I have tried passing the DB values through a cleaning function to replace line breaks ala:</p>
  
  <pre><code>private string CleanJavaScriptString( string stringToClean )
  {
      string cleanString = stringToClean.Replace( "'", "\'" );
  cleanString = cleanString.Replace( Environment.NewLine, "\n" );
  return cleanString;
  }
  </code></pre>
  
  <p>But this still outputs the actual line break in the code. How can I achieve this?</p>