You are currently offline, waiting for your internet to reconnect

PRB: "CS1010: Newline in Constant" Error Message When a String Contains a </SCRIPT> Tag in the Inline Code

This article has been archived. It is offered "as is" and will no longer be updated.
SYMPTOMS
When you try to browse an .aspx page with inline code that contains the </SCRIPT> HTML tag, you may receive the following error message:

Server Error in '/<applicationname>' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1010: Newline in constant
WORKAROUND
To work around this problem, split the </SCRIPT> tag in two or more strings such as "<" + "/SCRIPT>", and then use inside script blocks as follows:
   private void Page_Load(object sender, System.EventArgs e)    {      string strValue = "Test value";      string strAll = "<SCRIPT lanquage='JScript'>window.alert('" + strValue + "');<"+"/SCRIPT>";          }
STATUS
This behavior is by design.
MORE INFORMATION

Steps to Reproduce the Problem

  1. Start Microsoft Visual Studio .NET. Use Microsoft Visual C# .NET to create a new ASP.NET Web Application project.

    By default, WebForm1.aspx is created.
  2. In Design view, right-click WebForm1.aspx, and then click View HTML Source.
  3. Replace the existing HTML code with the following code:
    <%@ Page%><script runat="server">    private void Page_Load(object sender, System.EventArgs e)    {      string strValue = "Test value";      string strAll = "<SCRIPT lanquage='JScript'>window.alert('" + strValue + "');</SCRIPT>";          }</script><HTML>  <HEAD>  <title>Test</title>  </HEAD><body bgColor=#FFFFFF><form id="test" method="post" runat="server"><TABLE id=Table1 cellSpacing=0 cellPadding=0 border=0>Test Page</TABLE></form></body></HTML>
  4. On the Debug menu, click Start to run the application.

    You may receive the error message that is mentioned in the "Symptoms" section.
REFERENCES

For more information about writing a script that writes a script in Microsoft Internet Explorer or in ASP.NET, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/sxbe1ea4(vs.71).aspx

For more information about the design pattern for passing values between Web Form pages by using code inline, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/6c3yckfw(vs.71).aspx
Properties

Article ID: 827420 - Last Review: 12/08/2015 04:28:18 - Revision: 1.4

  • Microsoft ASP.NET 1.0
  • Microsoft ASP.NET 1.1
  • kbnosurvey kbarchive kbwebforms kberrmsg kbscript kbprb KB827420
Feedback