Microsoft KB Archive/821345

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

Article ID: 821345

Article Last Modified on 7/25/2003

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



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 (&amp;). When this problem occurs, the compiler may raise an error.



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:  Start Microsoft Visual Studio .NET. Create a new ASP.NET Web Application project in the following location:

http://localhost/TestApp

By default, WebForm1.aspx is created. Drag a HyperLink ASP.NET server control to WebForm1.aspx. In Design view, right-click WebForm1.aspx, and then click View Code.  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 & &quot;/WebForm2.aspx&quot; End Sub 



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



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET.</li> Create a new ASP.NET Web Application project in the following location: http:

http://localhost/TestApp

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

Notice that the ampersand characters have been converted to entities.</li></ol>

<div class="references_section">