Mick
Mick

Reputation: 161

Unexpected character sequence for <!-- in Asp.net/VB

I've inherited a VB website (I'm a C# developer by trade) and need to do some changes. On loading it into VS2010 it won't compile/run because it has a <!-- --> pair surrounding some code in the style section of each form and VS is saying this is an unexpected character sequence.

I'm assuming it's a vb comment tag, but I've Googled it to no effect and would very much appreciate some help with either making VS accept them, or advice on what to change them to so the original intent is not lost. NB - they appear around 100 times in the code so the former solution would be preferred!

I've tried <%-- which I use in C# but that doesn't appear to work either.

Example:

<html>
<head>
    <title>
        <%=Session("PAGE_TITLE")%></title>
    <link href="../../css/sc_english.css" rel="stylesheet" type="text/css" />
    <asp:Literal ID="stylesheet1" runat="server" />
    <style type="text/css">
<!--
body {
    margin-left: 10px;
    margin-top: 0px;
    margin-right: 10px;
    margin-bottom: 0px;
}
-->
</style>
</head>

Upvotes: 1

Views: 1432

Answers (1)

Justin Wignall
Justin Wignall

Reputation: 3510

<!-- --> is an html (and xml,xhtml etc.) comment block.

Sometimes the visual studio designer 'sync'ing can get confused if the comment block contains asp code.

<%' Commented stuff here %>

is a vb.net comment similar to <%-- in c#


After code sample posted...

The html comment has been placed inside the css styles, it should really be either

<!--
    <style type="text/css">

body {
    margin-left: 10px;
    margin-top: 0px;
    margin-right: 10px;
    margin-bottom: 0px;
}
</style>
-->

or

 <style type="text/css">
/*
body {
    margin-left: 10px;
    margin-top: 0px;
    margin-right: 10px;
    margin-bottom: 0px;
}
*/
</style>

i.e. use the html comment to comment out the html tag or use css comment block /* ... */ to comment out unwanted css styles.

A well crafted regex find-replace or simple work by hand on all affected files will be required to get it sorted correctly I guess.

VS is doings it's job correctly - your other option is to turn off this warning but I would suggest having valid pages is a more sensible goal.

Upvotes: 1

Related Questions