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



The information in this article applies to:

  • Microsoft ASP.NET (included with the .NET Framework) 1.0
  • Microsoft ASP.NET (included with the .NET Framework 1.1)

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://msdn.microsoft.com/library/en-us/jscript7/html/cautions.asp

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://msdn.microsoft.com/library/en-us/cpguide/html/cpconpassingservercontrolvaluesbetweenpages.asp

Modification Type:MajorLast Reviewed:10/3/2003
Keywords:kbWebForms kberrmsg kbScript kbprb KB827420 kbAudDeveloper