Page_Load Fires Twice

Page_Load Fires Twice even in the Northwind samples. What’s the deal with this behavior? It causes the code that generates the pdf to run twice.

Thanks,
David

Dear David,

I can’t find the event where Page-Load fires twice; either in the component or the demos. Please advise.

Are you setting a break point in Page_Load?

When I remove Response.End() or pdf.Save(Response) the behavior stops.

Here is my work around to the problem…

pdf.Save(Response);

// Work around to prevent Page_Load from executing twice…
byte[] bBuffer = new byte[(int)pdf.GetBuffer().Length];
bBuffer = pdf.GetBuffer();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType=“application/pdf”;
Response.BinaryWrite(bBuffer);

Response.End();

I think the problem is in the response header. Is there something happening in the Pdf.Save method that is causing the problem?

Also, the documentation use the following example that is not correct…
Example

Pdf pdf = new Pdf();
pdf.BindXML(“C:/xml/Test.xml”,null);
byte[] buf = pdf.GetBuffer();

It should be…

Pdf pdf = new Pdf();
pdf.BindXML(“C:/xml/Test.xml”,null);
byte[] buf = new byte[(int)pdf.GetBuffer().Length];
buf = pdf.GetBuffer();



This also works and is less code…

pdf.Save(Response);

// Work around…
Response.ClearHeaders();
Response.ContentType=“application/pdf”;

Response.End();

Something is happening with the response header.

Why are you setting Response.Expires in the Save method? You should not be doing this!!!

Is it possible the browser is actually making two page requests because of security issues with response headers changing?

David

Dear David,

Thanks for your consideration.

We decided to remove the Pdf.Save(HttpResponse) method. You can use the Pdf.Save(Stream) method to write the generated pdf to the web browser like the following code:

[C#]

Pdf pdf = new Pdf();
pdf.BindXML(“C:/xml/Test.xml”,null);Response.ClearContent();
Response.ClearHeaders();
Response.ContentType=“application/pdf”;
pdf.Save(Response.OutputStream);
Response.End();

[Visual basic]

Dim pdf As Pdf = New Pdf()
pdf.BindXML(“C:/xml/Test.xml”,Nothing)Response.ClearContent()
Response.ClearHeaders()
Response.ContentType=“application/pdf”
pdf.Save(Response.OutputStream)
Response.End()

Pdf.Save(HttpResponse) method will be removed in August 2004.

Dear Customers,

As Pdf.Save(HttpResponse) uses System.Web.dll it’s inappropriate for users who use Aspose.Pdf.dll in Windows forms applications only.

In this case Visual Studio .Net will complain The type ‘System.Web.HttpResponse’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Web’ if you try to build your Windows forms applications. It’s not a good practice fur us to have the user add a reference to System.Web into his Windows Applications.

So, today we declare that Pdf.Save(HttpResponse) is obsolete. Please don’t use it any more. Instead, use its overrides Save(string) or Save(Stream). If it is any of your current code, please try to modify it before August 2004.

Thanks for your tolerance and cooperation.

We use the Save(HttpReponse) method in our code to write the PDF directly into the output stream from a wen site and to force it to be displayed in the user’s browser (using Acrobat reader).

I am sure that we can achieve the same effect using the Save(Stream) method, it would be nice to see an example in you documentation which shows all of the work to achieve this goal. (I have not investigated enough to know exactly what is neede as I just saw your post.)

The example, should show the .axpx (containing no displayable HTML), a Page_Load that sets the correct properties in the HttpResponse and saves the output to the response’s output stream.

Thanks,
Tony