1

For the paging function on my webpage I will be using the symbol < which is a delimiter. When I run an html check it give me this error:

Line 747, Column 318: character "<" is the first character of a delimiter but occurred as data 
…quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))"><<   </a>

I know there has to be a way to get around this problem. Here is what my aspx code looks like:

 <td>
     <asp:LinkButton ID="PagerPrev" runat="server" CommandName="Page" CommandArgument="Prev"
    Text="<&nbsp;&nbsp;&nbsp;" ToolTip="Previous" />
</td>

If you see right after Text=" I used < and thats what the html error checker is picking up. Help is appreciated.

Filip
  • 3,257
  • 2
  • 22
  • 38
HereToLearn_
  • 1,150
  • 4
  • 26
  • 47
  • Please show us the generated source. – SLaks Nov 01 '12 at 12:57
  • Check question already asked. Using &alt; will not work. It will simply display the actual text string. not the < symbol http://stackoverflow.com/questions/8689804/w3c-validation-error-in-asp-net – UnitStack Nov 01 '12 at 13:00
  • Here: `Line 747, Column 318: character "<" is the first character of a delimiter but occurred as data …quot;, "", true, "", "", false, true))"><< ✉ This message may appear in several cases: •You tried to include the "<" character in your page: you should escape it as "<" •You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe. •Another possibility is that you forgot to close quotes in a previous tag. ` – HereToLearn_ Nov 01 '12 at 13:02
  • It is actually funny that you have html encoded the spatial char. and not the less than. `<` – JP Hellemons Nov 01 '12 at 13:06

3 Answers3

4

You have to encode it like you did with the non breaking spaces:

"<" is "&lt;"

The ">" would be "&gt;"

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • Thanks Olivier. That fixed my problem. I am new to all this so this is why I could not pick it up before and asked for help. Thanks everyone for your help my problem is solved. – HereToLearn_ Nov 01 '12 at 13:15
0

HTML-Encode the value using &lt;.

If you were updating the text programmatically you could use HttpServerUtility (exposed via the Server property of an ASP.NET page):

PagePrev.Text = Server.HtmlEncode(theValue);

HTML encoding makes sure that text is displayed correctly in the browser and not interpreted by the browser as HTML. For example, if a text string contains a less than sign (<) or greater than sign (>), the browser would interpret these characters as the opening or closing bracket of an HTML tag. When the characters are HTML encoded, they are converted to the strings < and >, which causes the browser to display the less than sign and greater than sign correctly.

In fact, you could even do this on page with inline scripting, but largely unnecessary.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
0

As others have said, if you use the “<” character in HTML content, it needs to be escaped e.g. as &lt;.

A different approach is to use other characters. In normal language, “<” means just “less than”. The idea of going backward or forward is perhaps better conveyed using arrow characters such as “←” e.g. as follows:

<style>
.arrow { font-weight: bold; font-family: Verdana; }
</style>
<a href="..." title="previous page" class="arrow">&larr;</a>
Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390