g5insider
g5insider

Reputation: 119

Why do certain tags go a new line when using HtmlTextWriter?

I'm having a bit of a hard time trying to format my HTML when using HtmlTextWriter. It seems that some tags will automatically go to a new line and some won't.

Is there a way to stop this from happening so all tags are created equally and leave the formatting completely up to me?

In my particular case I'm building out a <ul>'s and <li>'s for a custom HTML Sitemap.

The immediate tag that comes after an <ul> will wrap to a new line. This is not the case for a <li> tag.

If anyone needs clarification please ask question.

Upvotes: 4

Views: 1341

Answers (1)

Luaan
Luaan

Reputation: 63732

Are you using RenderBeginTag? That method will handle some things automatically, and among other things, it will put line breaks (and indentation) in elements that aren't inline (e.g. ul versus span).

If you want to do the rendering manually, use WriteBeginTag("ul") or WriteFullBeginTag("ul") instead.

Note that WriteBeginTag will still handle indentation. However, you have full control over that if you only use the WriteXXX methods.

In the end, though, do those endlines really bother you at all? You do use compression, right? The overhead usually isn't very significant...

Upvotes: 2

Related Questions