Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nathan Sokalski - 03 Aug 2007 19:13 GMT
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.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

tomisarobot@gmail.com - 03 Aug 2007 19:31 GMT
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.
Milosz Skalecki [MCAD] - 04 Aug 2007 00:36 GMT
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
Signature

Milosz

> 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>
[quoted text clipped - 8 lines]
> so there shouldn't be a difference in how the browser renders them. Does
> anybody have any comments on this? Thanks.
Nathan Sokalski - 05 Aug 2007 04:05 GMT
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.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> Hi Nathan,
>
[quoted text clipped - 26 lines]
>> so there shouldn't be a difference in how the browser renders them. Does
>> anybody have any comments on this? Thanks.
marss - 06 Aug 2007 08:41 GMT
> 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
Nathan Sokalski - 08 Aug 2007 02:23 GMT
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>
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

>> All they really need to do
>> is add a property to HtmlGenericControl like IsSelfClosingTag that
[quoted text clipped - 16 lines]
> Regards, Mykola
> http://marss.co.ua
marss - 08 Aug 2007 09:20 GMT
> 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
Nathan Sokalski - 12 Aug 2007 02:21 GMT
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.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

>> I do not believe that is completely correct. As I mentioned in my
>> original
[quoted text clipped - 16 lines]
> Regards, Mykola
> http://marss.co.ua
marss - 13 Aug 2007 07:02 GMT
> 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
[quoted text clipped - 29 lines]
> > Regards, Mykola
> >http://marss.co.ua

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.