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.

BUG: Ampersand Character in an Attribute Value Is Converted to an Entity When You Switch from Design View to HTML View


View products that this article applies to.

Symptoms

You have ampersand character (&) in an attribute value of an ASP.NET server control. When you switch from HTML view to Design view in Microsoft Visual Studio .NET, the ampersand character is converted to an entity (&). When this problem occurs, the compiler may raise an error.

↑ Back to the top


Workaround

To work around this problem, implement data that assigns functionality in a method in the codebehind file instead of in the .aspx file. To do this, follow these steps:
  1. Start Microsoft Visual Studio .NET.
  2. Create a new ASP.NET Web Application project in the following location:
    http://localhost/TestApp
    By default, WebForm1.aspx is created.
  3. Drag a HyperLink ASP.NET server control to WebForm1.aspx.
  4. In Design view, right-click WebForm1.aspx, and then click View Code.
  5. Change the code of the Page_Load event as follows:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          HyperLink1.NavigateUrl = Request.ApplicationPath & "/WebForm2.aspx"
    End Sub

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET.
  2. Create a new ASP.NET Web Application project in the following location: http:
    http://localhost/TestApp
    By default, WebForm1.aspx is created.
  3. In Design view, right-click WebForm1.aspx, and then click View HTML Source
  4. Replace the existing code in WebForm1.aspx with the following sample code:
    <%@ Page Language="vb" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
       <HEAD>
          <title>WebForm1</title>
          <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
          <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
          <meta content="JavaScript" name="vs_defaultClientScript">
          <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
          <script language="VB" runat="server">
             Sub Page_load(sender As Object, e As EventArgs)
                ' To  evaluate any <%# %> expressions in the page.   
                Page.DataBind()
             End Sub
          </script>
       </HEAD>
       <body MS_POSITIONING="GridLayout">
          <form id="Form1" method="post" runat="server">
             <asp:hyperlink id=HyperLink1 runat="server" NavigateUrl='<%# Request.ApplicationPath &  "/WebForm2.aspx"%>'>HyperLink</asp:hyperlink>
             <a href='<%= Request.ApplicationPath & "/WebForm1.aspx"%>'>link</a>
          </form>
       </body>
    </HTML>
    
  5. In HTML view, right-click WebForm1.aspx, and then click View Design.

    Note Do not save the WebForm1.aspx file before you switch to Design view.
  6. In Design view, right-click WebForm1.aspx, and then click View HTML Source.

    Notice that the ampersand characters have been converted to entities.

↑ Back to the top


References

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
316946� BUG: Visual Studio .NET Editor Malforms HTML Tags
For more information about data binding, visit the following Microsoft Web site:

↑ Back to the top


Keywords: KB821345, kbbug, kbhtml, kbwebforms, kbdatabinding, kbpending

↑ Back to the top

Article Info
Article ID : 821345
Revision : 5
Created on : 7/25/2003
Published on : 7/25/2003
Exists online : False
Views : 415