HTML White Space from Hidden Controls

Discussion in 'ASP .Net' started by Don Miller, Apr 17, 2007.

  1. Don Miller

    Don Miller Guest

    When an ASP.NET 2.0 web page is rendered with multiple web controls hidden
    from view (.visible=false) there is a noticeable gap between a rendered
    element (like a table) and the next visible element (e.g. a button). When I
    look at the HTML source code there is nothing there except white space (see
    below).

    First of all, I thought browsers ignore white space and condense it down to
    one space, but most of all, how can controls be hidden from the rendered
    view so that the controls don't leave gaps between elements (like the
    controls are there but they are not)?

    Thanks for any tips.

    </tr></table>








    <input type="submit" name="btnStartOver" value="Start Over"
    id="btnStartOver" />
     
    Don Miller, Apr 17, 2007
    #1
    1. Advertising

  2. Don Miller

    bruce barker Guest

    tables are a block element with a margin and a border, no whitespace.
    set these to 0px and the table will not add any space.

    -- bruce (sqlwork.com)

    Don Miller wrote:
    > When an ASP.NET 2.0 web page is rendered with multiple web controls hidden
    > from view (.visible=false) there is a noticeable gap between a rendered
    > element (like a table) and the next visible element (e.g. a button). When I
    > look at the HTML source code there is nothing there except white space (see
    > below).
    >
    > First of all, I thought browsers ignore white space and condense it down to
    > one space, but most of all, how can controls be hidden from the rendered
    > view so that the controls don't leave gaps between elements (like the
    > controls are there but they are not)?
    >
    > Thanks for any tips.
    >
    > </tr></table>
    >
    >
    >
    >
    >
    >
    >
    >
    > <input type="submit" name="btnStartOver" value="Start Over"
    > id="btnStartOver" />
    >
    >
     
    bruce barker, Apr 18, 2007
    #2
    1. Advertising

  3. Hi,

    Don Miller wrote:
    > When an ASP.NET 2.0 web page is rendered with multiple web controls hidden
    > from view (.visible=false) there is a noticeable gap between a rendered
    > element (like a table) and the next visible element (e.g. a button). When I
    > look at the HTML source code there is nothing there except white space (see
    > below).
    >
    > First of all, I thought browsers ignore white space and condense it down to
    > one space, but most of all, how can controls be hidden from the rendered
    > view so that the controls don't leave gaps between elements (like the
    > controls are there but they are not)?
    >
    > Thanks for any tips.
    >
    > </tr></table>
    >
    >
    >
    >
    >
    >
    >
    >
    > <input type="submit" name="btnStartOver" value="Start Over"
    > id="btnStartOver" />


    Many browsers render new lines in the HTML codes as whitespaces in the
    rendered view. The reason is that in a block of text, when you have a
    new line in the text, the browser wants to separate the words.
    Unfortunately, it also often creates unwanted white spaces when you want
    your HTML code to be nicely formatted.

    To avoid this, the only certain way is to write

    > </tr></table><input type="submit"

    name="btnStartOver"
    value="Start Over"
    id="btnStartOver" />

    HTH,
    Laurent
    --
    Laurent Bugnion [MVP ASP.NET]
    Software engineering, Blog: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, MVP, Apr 19, 2007
    #3
  4. Don Miller

    Don Miller Guest

    Thanks, I didn't know (or expect) that. I guess that also means that I can't
    include new lines in my ASP.NET code (for coding formatting) but should make
    sure all tags are end-to-end.

    "Laurent Bugnion, MVP" <> wrote in message
    news:...
    > Hi,
    >
    > Don Miller wrote:
    >> When an ASP.NET 2.0 web page is rendered with multiple web controls
    >> hidden from view (.visible=false) there is a noticeable gap between a
    >> rendered element (like a table) and the next visible element (e.g. a
    >> button). When I look at the HTML source code there is nothing there
    >> except white space (see below).
    >>
    >> First of all, I thought browsers ignore white space and condense it down
    >> to one space, but most of all, how can controls be hidden from the
    >> rendered view so that the controls don't leave gaps between elements
    >> (like the controls are there but they are not)?
    >>
    >> Thanks for any tips.
    >>
    >> </tr></table>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >> <input type="submit" name="btnStartOver" value="Start Over"
    >> id="btnStartOver" />

    >
    > Many browsers render new lines in the HTML codes as whitespaces in the
    > rendered view. The reason is that in a block of text, when you have a new
    > line in the text, the browser wants to separate the words. Unfortunately,
    > it also often creates unwanted white spaces when you want your HTML code
    > to be nicely formatted.
    >
    > To avoid this, the only certain way is to write
    >
    > > </tr></table><input type="submit"

    > name="btnStartOver"
    > value="Start Over"
    > id="btnStartOver" />
    >
    > HTH,
    > Laurent
    > --
    > Laurent Bugnion [MVP ASP.NET]
    > Software engineering, Blog: http://www.galasoft-LB.ch
    > PhotoAlbum: http://www.galasoft-LB.ch/pictures
    > Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Don Miller, Apr 19, 2007
    #4
  5. H5,

    Don Miller wrote:
    > Thanks, I didn't know (or expect) that. I guess that also means that I can't
    > include new lines in my ASP.NET code (for coding formatting) but should make
    > sure all tags are end-to-end.


    In most cases, it doesn't matter, because the white spaces are not
    visible. It does matter, however, when you have, for example, an image
    in a DIV, and the DIV must "hug" the image as tightly as possible

    So, generally, you may format your code as you wish, even with
    indentation, new lines, etc... but in cases where white spaces suddenly
    appear in the rendered view, then it's a good idea to append the tags
    without new lines in between (only where necessary).

    HTH,
    Laurent
    --
    Laurent Bugnion [MVP ASP.NET]
    Software engineering, Blog: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, MVP, Apr 19, 2007
    #5
    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. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,987
    Bryan Bullard
    Jul 11, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,812
    Stephen Horne
    Oct 27, 2003
  3. Ian Bicking
    Replies:
    2
    Views:
    1,114
    Steve Lamb
    Oct 23, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    789
    Michael Hudson
    Oct 24, 2003
  5. Ben C
    Replies:
    6
    Views:
    2,254
    Leif K-Brooks
    Jan 28, 2007
Loading...

Share This Page