RenderControl not writing complete markup

R

Ralf Ziller

I have a GridView which I want to send via email. I have overriden
VerifyRenderingInServerForm to allow this.
But if I call RenderControl to write the html markup in a memory stream I
only get part of the markup. If I do a subsequent call to RenderControl the
missing markup is rendered and the Control is rendered a second time (again
it stops inside the markup).

MemoryStream ms = new MemoryStream();
TextWriter tw = new StreamWriter(ms);
HtmlTextWriter htw = new HtmlTextWriter(tw);
GridView2.RenderControl(htw);

I noticed the control will only write 1024 bytes to the Memorystream. So I
had the idea of increasing the write buffer.
TextWriter tw = new StreamWriter(ms, System.Text.Encoding.UTF8, 2048);
but then there was nothing written to the stream.
After some experimenting I found out that a small increase of the buffer
will write more bytes to the stream but a larger increase will write none.
The maximum buffer size that still writes to the stream is the needed length
for the complete html markup minus one.
So, in my case
TextWriter tw = new StreamWriter(ms, System.Text.Encoding.UTF8, 1313);
will write the complete markup excluding the final >.
Are there any solutions to this (I wouldn't like to use code to get the
buffersize needed and add the final >)? This seems to be a bug...

TIA
Ralf
 

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,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top