Visual Studio changing the &

mhsueh001

Freshman
Joined
Dec 31, 1969
Messages
41
Ok, I'm not sure this is really and ASP.NET problem, it's more of a Visual Studio Environmental problem.

VS keeps changing my "&" to "&" on the html portion of my asp.net pages, and of course this is incorrect. I have to do a find and replace for all the & back to & each time I load up a page and this is getting really annoying.
I can't find where in the preferences or options to keep visual studio from doing this. Any help would be greatly appreciated.

Thanks.
 
Why do you want to use "&" rather than "&amp"? because HTML "&amp" = "&" display in browser, so you no need to replace it back to "&". The output for both are same = "&"
 
I think the problem occurs when you try to paste a piece of vb code in an asp page when the page is in design view, vs.net will consider it as html code and will change the & to &amp. Now even if you change to html view and change the &amp to &, vs.net will change it back to &amp.........strange
 
This is indeed the problem

wessamzeidan said:
I think the problem occurs when you try to paste a piece of vb code in an asp page when the page is in design view, vs.net will consider it as html code and will change the & to &amp. Now even if you change to html view and change the &amp to &, vs.net will change it back to &amp.........strange

As described by wessamzeidan, this is the problem.

For example I want to link to my style sheet in my Application path's root directory:
I type:
<link rel="stylesheet" href='<%= Request.ApplicationPath & "/MyStyles.css" %>' type="text/css" >
If I run it immediately it works. However the minute I begin to edit something on the aspx page it changes the line above to:
<link rel="stylesheet" href='<%= Request.ApplicationPath & "/MyStyles.css" %>' type="text/css" >

This gives me an error because it doesn't recognize & as proper vb coding. It does this EVERY time I modify the page and I have to go in and remodify it.

It's getting really annoying.

Any idea where I can turn off the checking for this. Please don't tell me it's the intellisense cuz I don't want to turn that off. ;)
 
Change the auto-formating

Goto Tools/Options.../ Text Editor / "HTML/XML" / Format

And then remove the autoformating checkbox (2 first).
 
I've tried to duplicate that problem and cannot. Every time I paste or edit, the & stays as an & and never changes to an &. Therefore, my settings must be different from yours that's causing this. I have intellisense turned on, so that can't be causing it.

My options are as follows: I have the 'Pretty Listing' turned off for VB code but that should only affect your code behind pages. I have the 'Apply Automatic Formatting' for HTML/XML turned off for both 'When saving document' and 'When switching from Design to HTML/XML view'. The HTML Specific and XML Specific options are all enabled (checked).

Hopefully that will help, if not then maybe this is something controlled elsewhere?
 
Arch4ngel

Arch4ngel said:
Change the auto-formating

Goto Tools/Options.../ Text Editor / "HTML/XML" / Format

And then remove the autoformating checkbox (2 first).

I did this, but it didn't solve my problem. It's still replacing the & with &
Thanks though.
 
akiaz said:
I've tried to duplicate that problem and cannot. Every time I paste or edit, the & stays as an & and never changes to an &. Therefore, my settings must be different from yours that's causing this. I have intellisense turned on, so that can't be causing it.

My options are as follows: I have the 'Pretty Listing' turned off for VB code but that should only affect your code behind pages. I have the 'Apply Automatic Formatting' for HTML/XML turned off for both 'When saving document' and 'When switching from Design to HTML/XML view'. The HTML Specific and XML Specific options are all enabled (checked).

Hopefully that will help, if not then maybe this is something controlled elsewhere?

It's not a hard problem to duplicate so follow this.
Create a new web project with Visual basic.Net Call it the default WebApplication1 or what ever.

Go to the WebForm1.aspx that is created and View it in html format
(Double Click on WebForm1.aspx) On the bottom of the form designer you see two buttons that allow you to switch between Design view and HTML view.
Switch to the HTML view since it default to start up in the Design view.

Add this line:
<link rel=stylesheet type=text/css href='<% Request.ApplicationPath & "/Styles.css" %>' >

Which will link the cascading style sheet to the web page for your usage.

I typically add this line between the <HEAD> and </HEAD> tags.
For example:
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<!-- I ADDED THE LINE BELOW -->
<link rel=stylesheet type=text/css href='<% Request.ApplicationPath & "/Styles.css" %>' >
</HEAD>

This allows me to use the cascading style sheet.

Now go back go design view for the WebForm1.aspx

Simply drag on a Web Forms Label Control. Or make any modification that causes the form to have that little * appear in the name indicating that the page has been modified.

Now switch back to the HTML view of the page and voila the original line now says

<link rel=stylesheet type=text/css href='<% Request.ApplicationPath & "/Styles.css" %>' \>



Pissing me off... Of course they say better Pissed off than pissed on.
 
OK, I followed your method and duplicated what you said.

Well, i never use the design view is VS cause I think it is a true piece of garbage. The solution is to code your page only in HTML view. Not an elegant solution though, sorry. It appears that the designer modifies more code than just what is inserted when dropping the label control. I have always noticed that just switching between design mode and HTML view can cause this, which is why I set HTML view as default and never touch the Design button. I am using VS 2002 so I don't know if this is the same with VS 2003. Are you using the new VS version?
 
But there must be a solution for this. I have another similar problem too. Some times, when I edit using html view and switch back to design view, vs.net crashes. When this happens, the only way I can edit my aspx file is by using dreamweaver or some other text editor
 
I thought in ASP.NET, mix together HTML code and server side VB code is not recommended? Why not separate it? As what I know, the performance will be better

example,

In aspx:
<Link rel="stylesheet" type="text/css" id="myID" runat="server" />

Visual Basic:
'In Class Level
Protected WithEvents myID As HtmlGenericControl

'In Event (Page_Load)
myID.Attributes.Add("href") = "default.css"
 
bungpeng said:
I thought in ASP.NET, mix together HTML code and server side VB code is not recommended? Why not separate it? As what I know, the performance will be better

example,

In aspx:
<Link rel="stylesheet" type="text/css" id="myID" runat="server" />

Visual Basic:
'In Class Level
Protected WithEvents myID As HtmlGenericControl

'In Event (Page_Load)
myID.Attributes.Add("href") = "default.css"

As a note: The syntax in your Page_Load should be
myID.Attributes.Add("href", "default.css") 'At least that's the syntax in VB.NET

Sweet, that works well and keeps me from that headache.

I no longer see the style sheet being applied instantly as I work in Design View, which I liked, but I'd rather work this way than have to remember to change the & back to & each time.

Thanks for your solution!
 
Back
Top