0

I want to call an aspx page that creates a PDF file from current aspx page but I don't want to wait for the other page to complete. It takes a long time for the PDF to be created and the user doesn't care that it is being created.

I tried Server.TransferRequest and that seems to work except the page I am working on shows the "response.write" from the page I called. I want the called page to simply run and I don't want to know about it after I call it.

How can I simply execute another page and "forget it". Unfortunately, the PDF utility is required to be run on an actual aspx page and cannot be called in a function.

Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

    Response.write("This should show on the current page")

    Server.TransferRequest("/Invoicing/PDFGenerator.aspx")

    Response.write("This second line should show on the current page but does not")

End Sub

I've looked at async info but it is not clear if that is what I have to do here.

Joe Schmucker
  • 173
  • 1
  • 10
  • Put `Server.TransferRequest` last. It *is* a transfer. I'm guessing that won't work for you, but why? – wazz Jun 14 '18 at 22:57
  • I see your point. The purpose of the transfer is to actually transfer to the other page. I'm trying to find a work-around to actually transferring the current http context. I just want to "call it and forget it" and not have it affect the page I am on. When the other page is done (the one being called), it is the reponse buffer from the OTHER page that is being posted onto the current page. I want my current page to be presented as if no Server.TransferRequest happened. There is hopefully another way to do it without the transfer command. If not, the customer will just have to wait. :-( – Joe Schmucker Jun 15 '18 at 13:38
  • I was just doing some work on files and came across [this](https://learn.microsoft.com/en-us/dotnet/standard/io/asynchronous-file-i-o). Maybe this approach could work (async/await). I don't know much about it, you'll have to dig in to see if it's applicable. – wazz Jun 16 '18 at 02:21
  • Thank you for the recommendations. I appreciate you folks taking the time to help me. – Joe Schmucker Jun 18 '18 at 14:35

1 Answers1

0

The iframe approach might work. Create a hidden iframe on your page and load the .aspx page into it as needed.

// add query string if needed.
$(".hiddenIframe").attr("src", "pdf-generator.aspx?fname=" + fname + "&fid=" + fid);

When the page is loaded (via 'src') the code-behind will execute.

wazz
  • 4,953
  • 5
  • 20
  • 34