Article ID: 316174 - Last Review: February 11, 2004 - Revision: 2.6

PRB: The </SCRIPT> Tag Is Treated As a Closing Tag When Inside a Quoted String

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q316174

On This Page

Expand all | Collapse all

SYMPTOMS

When you use a </SCRIPT> Hypertext Markup Language (HTML) tag inside a quoted string, the tag is treated as a closing tag rather than as a portion of the string.

RESOLUTION

To work around this behavior, do not directly use the </SCRIPT> tag inside a script section. Instead, you can use alternatives such as the following tag:
chr(60) & "/SCRIPT>
				

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Copy the following code to a Script.aspx page, and then save it to your Web server:
    <script language="vb" runat="server" id="Script1">
        Private Sub scripTest(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    	Dim myStr as String
    				
    	myStr = "</script>"
    
        End Sub
    </script>
    
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    	</HEAD>
    	<body>
    		<form id="Form1" method="post" runat="server">
    			<asp:Button OnClick="scripTest" id="Button1" style="Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 62px" runat="server" Text="Button" Width="273px" Height="94px"></asp:Button>
    		</form>
    	</body>
    </HTML>
    
    					
  2. Reference the test page in your Web browser, and the following error message appears:
    Compiler Error Message:BC30648: String constants must end with a double quote
  3. Modify the Script.aspx page, and then change the following line of code from:
    myStr = "</script>"
    					
    to:
    myStr = chr(60) & "/script>"
    					
    Note that the Script.aspx page functions as expected when you change the code.

APPLIES TO
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
  • Microsoft Active Server Pages 4.0
Keywords: 
kbprb kbwebforms KB316174