Why do I not need a closing tag

T

Tony Johansson

Hello!

In the first line I have no closing tag for the bold tag and I don't get any
compile error why ?
The compiler would be able to see that the start bold tag has no closing tag
and would give me a compile error or
at least a compile warning.


protected void Page_Load(object sender, EventArgs e)
{
test.InnerHtml = "To <b>bold text use the";
test.InnerHtml += Server.HtmlEncode("<b>") + " tag";
}

//Tony
 
R

Rick Lones

Tony said:
Hello!

In the first line I have no closing tag for the bold tag and I don't get any
compile error why ?
The compiler would be able to see that the start bold tag has no closing tag
and would give me a compile error or
at least a compile warning.


protected void Page_Load(object sender, EventArgs e)
{
test.InnerHtml = "To <b>bold text use the";
test.InnerHtml += Server.HtmlEncode("<b>") + " tag";
}

Because you are running a C# compiler, not an HTML verifier. Syntactically your
example is just manipulating text strings and all the compiler will care about
is that the quote delimiters match up properly.

If you code, e.g.,
string importantDocument = "Decalarton of Independense";
would you expect the compiler to correct your spelling?
 
A

Arne Vajhøj

In the first line I have no closing tag for the bold tag and I don't get any
compile error why ?
The compiler would be able to see that the start bold tag has no closing tag
and would give me a compile error or
at least a compile warning.

protected void Page_Load(object sender, EventArgs e)
{
test.InnerHtml = "To<b>bold text use the";
test.InnerHtml += Server.HtmlEncode("<b>") + " tag";
}

ASP.NET does not validate HTML - neither literal HTML in the .aspx or
something generated in the .aspx.cs.

Visual Studio does validate the liteal HTML in the .aspx since
2005 version. But it does not check something generated in the .aspx.cs.

Note that most browsers are very lenient about HTML syntax. The browser
will do its best to handle the missing </b>.

If you are outputting XHTML then the browser should object (I have
not tested if they actually do).

Smart people have created XHTML validators as a HTTP module to make
it easier to find problems during development.

http://www.thejoyofcode.com/validator_module.aspx

Maybe you would find something like that useful.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top