Although you can write directly to Response.OutputStream , this can sometimes mask errors. Instead, I recommend that you write to another stream, such as FileStream or MemoryStream . If you use the latter, you can also save the MemoryStream to an array of bytes, which you can pass between functions. The code below shows this, and also uses a disposition template for disposable objects.
The above may still break down on you depending on how you do your control. You may receive a message that says:
Control 'xxx' of type 'yyy' must be placed inside a form tag with runat=server
You can get around this by overriding the VerifyRenderingInServerForm page.
public override void VerifyRenderingInServerForm(Control control) { }
Chris Haas Jun 18 '13 at 14:39 2013-06-18 14:39
source share