Al Kepp
Al Kepp

Reputation: 5980

Is it possible to 'turn off' indentation in asp.net controls?

When I use built-in controls in asp.net I can see many tab characters added at start of each line of the generated html output. Is it possible to 'turn of' these? I'd like to get rid of this waste.

For example when I use GridView control, it generates <table> tag which looks like this:

<div>
        <table>
                <tr>
                        <th>...</th>
                </tr>
                <tr>
                        <td>...</td>
                </tr>
                ...
        </table>
</div>

But I want to see this:

<div>
<table>
<tr>
<th>...</th>
</tr>
<tr>
<td>...</td>
</tr>
...
</table>
</div>

I wonder who designed this silly stuff. Although it is "just a few bytes", it sends many unneeded waste over internet if you look at it from a long time period point of view. (I understand that indentation makes it more readable, but still at least those inner <th> and <td> tags are a bit too much indented.)

Or do you think I am completely wrong? [Are those tabs important for The World?]

Upvotes: 0

Views: 252

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038800

I wonder who designed this silly stuff

Microsoft Corporation.

Or do you think I am completely wrong?

I think you are completely wrong. HTML is to be read and interpreted by browsers. You, as a developer, could use developer tools such as FireBug to inspect the actual DOM tree in a nice way. Humans/users don't give a s..t about how your HTML is indented. They look at the final product rendered by the browser and this is what you should be focusing on. Actually in production in order to optimize bandwidth you should compress your HTML and remove all white-spaces. Could be done with custom response filters.

Upvotes: 2

jwheron
jwheron

Reputation: 2562

Personally, when I write a page (I use the Repeater control, so there's a bit of a difference), I always indent my HTML. Yes, even the content within the <th> and <td> tags.

I can understand your point (especially when we talk about using gzipped and minified copies of JavaScript libraries) when you're talking about a production application that's never debugged. However, without HTML indentation, it would be incredibly difficult for me to unwind problems in my layout or errors I made when I wrote CSS or HTML properties.

Upvotes: 0

Related Questions