Different renderings of <br/> and <br></br> in IE6

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

Something that I recently noticed in IE6 (I don't know whether it is true
for other browsers or versions of IE) is that it renders <br/> and <br></br>
differently. With the <br/> version, which is what most people use when they
write static code (some people use <br>, but with xhtml you are required to
close all tags), IE6 simply breaks to the next line like it is supposed to.
However, with <br></br>, which is what is sometimes generated by certain
server-side code (for example, ASP.NET/VB.NET's HtmlGenericControl("br")
class renders <br></br>), an extra blank line is rendered. IE6 appears to be
interpreting <br></br> as <br/><br/>, but <br/> and <br></br> are supposed
to be the same thing (<br/> is just the self closing syntax of <br></br>),
so there shouldn't be a difference in how the browser renders them. Does
anybody have any comments on this? Thanks.
 
T

tomisarobot

br is not an encapsulation element, like img.

<br /> - transitional, usually your best practice, mind the space in
there, this should work in most older browsers.
<br/> - strict, wont work in some older browsers. unless your entire
site must validate as strict use transitional.

I've never seen <br></br> anywhere, I don't believe it exists in any
spec.
 
G

Guest

Hi Nathan,

In addition to Tomi's reply, please note HtmlGenericControl is not invented
for <br> tag but span/body/div/font. Alternatively, use
LiteralControl("<br>") / LiteralControl("<br />") or WriteBreak() method of
the HtmlTextWriter class.

HTH
 
N

Nathan Sokalski

Thank you for that suggestion, but I would like to point out that I am not
designing a CustomControl, I am simply dynamically adding a line break to a
page. In my specific case, using the LiteralControl is good enough (which is
what I decided to do), but because that does not allow me access to
properties such as Clear that the br tag has, it can make it harder, or at
least more complicated, to write code in certain cases (it can be a pain to
generate the html by hand, even if it is simple). All they really need to do
is add a property to HtmlGenericControl like IsSelfClosingTag that specifies
whether or not the tag is self-closing. Is that really that much to ask?
Thanks.
 
M

marss

All they really need to do
is add a property to HtmlGenericControl like IsSelfClosingTag that specifies
whether or not the tag is self-closing. Is that really that much to ask?
Thanks.

Hi, Nathan
I guess it is not developer's affair to decide whether BR has or has
not additional slash. In HTML there are 2 types of tags: single(br,
hr, img ...) and paired (div, span ...). Whether a single tag will be
closed - solution depends on doctype declaration used in your pages.
If doctype is HTML4.0 (default in Visual Studio 2003) then br is
rendered <br>.
If doctype is XHTML (default in Visual Studio 2005) then br is
rendered <br/>.
Look here, maybe it will be helpful.
http://www.w3schools.com/xhtml/xhtml_html.asp

Regards, Mykola
http://marss.co.ua
 
N

Nathan Sokalski

I do not believe that is completely correct. As I mentioned in my original
posting, I have used methods in VB.NET that generate <br></br> and I could
not find a class that was a control, in other words, one that I could set
properties for that would determine the attributes of the generated tag. Are
there other classes and methods that can be used? Yes, there are classes
such as the Literal control, there is the WriteBreak() method if you are
creating a Control, but my point is that you cannot access the attribute
values through properties without extra manual parsing of the values. The
situation in which I wanted to use the <br/> tag as a server control was so
that I could dynamically set the visible property (when I showed/hid other
controls, I had to show/hide the <br/> in order to avoid extra whitespace).
My workaround was to use the Literal control, but this required me to set
the Mode and Text properties, which means longer code, which would not be
necessary if there was a class for the <br/> tag. I tested this in both IE6
and IE7, if you want to see the difference, simply view the following page
in your browser:

<html>
<body>
This line is next to the next line<br/>
This line is next to the previous line, but has a blank line before
the next line of text<br></br>
There is a blank line between this line and the previous line of
text
</body>
</html>
 
M

marss

I do not believe that is completely correct. As I mentioned in my original
posting, I have used methods in VB.NET that generate <br></br> and I could
not find a class that was a control, in other words, one that I could set
properties for that would determine the attributes of the generated tag.

Rendering HtmlGenericControl("BR") in the form of "<br></br>" is no
more than bug
and you should not exploit this and try to customize.

My workaround was to use the Literal control, but this required me to set
the Mode and Text properties, which means longer code, which would not be
necessary if there was a class for the <br/> tag.

Use LiteralControl from System.Web.UI namespace.
LiteralControl br = new LiteralControl("<br/>");


Regards, Mykola
http://marss.co.ua
 
N

Nathan Sokalski

Your code example of using the Literal control is great, except for one
thing: It does not set the Mode property to PassThrough, which is necessary
to avoid having the text converted to something that uses html character
codes such as &lt; and &gt;. Because the Mode property cannot be set in the
constructor, it requires an extra line of code. I think the message I am
trying to get across in this thread is that it should not require this much
extra code to simply add a server control that will usually have no
attributes and have nothing changed during runtime except the visible
property.
 
M

marss

Your code example of using the Literal control is great, except for one
thing: It does not set the Mode property to PassThrough, which is necessary
to avoid having the text converted to something that uses html character
codes such as < and >. Because the Mode property cannot be set in the
constructor, it requires an extra line of code. I think the message I am
trying to get across in this thread is that it should not require this much
extra code to simply add a server control that will usually have no
attributes and have nothing changed during runtime except the visible
property.

We are talking about two different conrols.
Not Literal control from System.Web.UI.WebControls namespace but
LiteralControl control from System.Web.UI namespace.

Regards, Mykola
http://marss.co.ua
 

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

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,842
Latest member
MableIwk73

Latest Threads

Top