By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Remove Whitespace when rendering Server Control

P: n/a
If you create a new server control, and override the Render method with the
following code:

protected override void Render(HtmlTextWriter output)
{
// <TABLE id="mytable">
output.AddAttribute(HtmlTextWriterAttribute.Id, "mytable");
output.RenderBeginTag(HtmlTextWriterTag.Table);

// <TR>
output.RenderBeginTag(HtmlTextWriterTag.Tr);

// <TD>
output.RenderBeginTag(HtmlTextWriterTag.Td);

// </TD>
output.RenderEndTag();

// </TR>
output.RenderEndTag();

// </TABLE>
output.RenderEndTag();
}

It produces the following code:

<table id="mytable">
<tr>
<td></td>
</tr>
</table>

But, due to a rendering bug in IE, I need it to be rendered without tabs or
line breaks like so:

<table id="mytable"><tr><td></td></tr></table>

First, just let me say I know I can use the HtmlTextWriter.Write method to
do this, but I need to use the built-in enumerations
(HtmlTextWriterAttribute, HtmlTextWriterStyle, HtmlTextWriterTag) as
demonstrated above.

Here is what I've tried:

- Setting HtmlTextWriter.Indent = 0. No effect.
- Setting HtmlTextWriter.NewLine = "" (or anything). No effect.
- Reinitializing the HtmlTextWriter like so: output = new
HtmlTextWriter(output, ""). This got rid of the tabs.
- Deriving from HtmlTextWriter to try to access the output stream in my
derived class and "strip" whitespace. Overrode the RenderBeforeTag,
RenderAfterTag, NewLine, CoreNewLine members. Didn't work. I probably
didn't follow this idea far enough. May be some merit here.

So, is there any possible way to use the HtmlTextWriter enumerations to
render HTML without tabs and line breaks? I am beginning to get worried that
MS did not consider my dilemma in their design (although they would have to
be immensely stupid to not account for their OWN IE rendering bug when
creating the HtmlTextWriter class). Please help!
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.