Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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

↑ Back to the top


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>";      
    }

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


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.

↑ Back to the top


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

↑ Back to the top


Keywords: KB827420, kbprb, kbscript, kberrmsg, kbwebforms

↑ Back to the top

Article Info
Article ID : 827420
Revision : 5
Created on : 5/17/2007
Published on : 5/17/2007
Exists online : False
Views : 357