Remove Whitespace when rendering Server Control

T

threecrans

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top