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

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Aug 3, 2007.

  1. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Aug 3, 2007
    #1
    1. Advertising

  2. Nathan Sokalski

    Guest

    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.
     
    , Aug 3, 2007
    #2
    1. Advertising

  3. 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
    --
    Milosz


    "Nathan Sokalski" wrote:

    > 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.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
    >
     
    Milosz Skalecki [MCAD], Aug 4, 2007
    #3
  4. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Milosz Skalecki [MCAD]" <> wrote in message
    news:...
    > 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
    > --
    > Milosz
    >
    >
    > "Nathan Sokalski" wrote:
    >
    >> 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.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >>
    >>
     
    Nathan Sokalski, Aug 5, 2007
    #4
  5. Nathan Sokalski

    marss Guest

    On 5 , 06:05, "Nathan Sokalski" <> wrote:

    > 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
     
    marss, Aug 6, 2007
    #5
  6. 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>
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "marss" <> wrote in message
    news:...
    > On 5 , 06:05, "Nathan Sokalski" <> wrote:
    >
    >> 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, Aug 8, 2007
    #6
  7. Nathan Sokalski

    marss Guest

    On 8 , 04:23, "Nathan Sokalski" <> wrote:
    > 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
     
    marss, Aug 8, 2007
    #7
  8. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "marss" <> wrote in message
    news:...
    > On 8 , 04:23, "Nathan Sokalski" <> wrote:
    >> 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, Aug 12, 2007
    #8
  9. Nathan Sokalski

    marss Guest

    On 12 , 04:21, "Nathan Sokalski" <> wrote:
    > 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.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/
    >
    > "marss" <> wrote in message
    >
    > news:...
    >
    > > On 8 , 04:23, "Nathan Sokalski" <> wrote:
    > >> 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


    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
     
    marss, Aug 13, 2007
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. No One

    Incorrect Mozilla renderings

    No One, Nov 16, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    434
    No One
    Nov 17, 2004
  2. Ivor O'Connor
    Replies:
    4
    Views:
    894
    Isofarro
    Nov 25, 2003
  3. long eddy

    Renderings

    long eddy, Jan 6, 2007, in forum: HTML
    Replies:
    3
    Views:
    416
    Neredbojias
    Jan 9, 2007
  4. Nathan Sokalski
    Replies:
    8
    Views:
    463
    marss
    Aug 13, 2007
  5. timothytoe
    Replies:
    4
    Views:
    170
Loading...

Share This Page