Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HTML White Space from Hidden Controls

Reply
Thread Tools

HTML White Space from Hidden Controls

 
 
Don Miller
Guest
Posts: n/a
 
      04-17-2007
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" />


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      04-17-2007
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" />
>
>

 
Reply With Quote
 
 
 
 
Laurent Bugnion, MVP
Guest
Posts: n/a
 
      04-19-2007
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
 
Reply With Quote
 
Don Miller
Guest
Posts: n/a
 
      04-19-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Laurent Bugnion, MVP
Guest
Posts: n/a
 
      04-19-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any programs to trim white space/ remove all white space in HTML file? Ben C HTML 6 01-28-2007 11:41 PM
Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok?? Christian Seberino Python 21 10-27-2003 04:20 PM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-24-2003 11:15 AM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-23-2003 07:07 AM
Stack space, global space, heap space Shuo Xiang C Programming 10 07-11-2003 07:30 PM



Advertisments