HOME - ABOUT

ASP.Net - Error: Newline in constant

09.07.07 @ 8pm

Here’s a tip from a few years ago. I was working in C# on an ASP.Net application and needed to run some Javascript code from the server side. That’s when I ran into the error.

I was trying to run something similar to the following code…

string sAlert = "";
this.RegisterClientScriptBlock("alert", sAlert);

I kept getting the error, “Compiler Error Message: CS1010: Newline in constant.” The line of code highlighted by Visual Studio was…

sAlert += "</script>";

What the…? I don’t see any new lines in there. After searching the web for quite a while, I came upon the solution. It’s totally stupid and makes no sense, but it works.

sAlert += "<" + "/script>";

I told you it was stupid and didn’t make any sense. Stuff like this is major pet peeve for me. Fighting with the user interface of an IDE or buggy compilers is the height of frustration and is in no way interesting or satisfying.

For all I know Microsoft fixed the problem in on the VS.Net service packs. I can never get back the time I spent finding this solution so I’m not going to look into it any further.

One Comment on “ASP.Net - Error: Newline in constant”

Leave a Comment