After ASP .Net Dynamically Rendered PDF, Cannot Change Page - asp.net

I have a page where the user enters some information. At the bottom of the page there is a checkbox that is disabled, that says they have read the PDF to be displayed. They click on a link which dynamically renders a PDF and is downloaded by the user. After downloading the PDF a Response.End() is issued, which means nothing else can be done on the page. I want to be able to enable the checkbox after the PDF is sent.
I have tried saving the data to the Session, opening a new window, and using the Session data to send the PDF from that new window. However, IE popup-blocker blocks it.
Any ideas?

Is there anyway to use jQuery/AJAX for this? If you did you could send the request to download the PDF via the AJAX request, and then re-enable the checkbox with javascript afterwards.

Related

HTML to PDF: Avoid having the download button in the downloaded PDF

I have an ASP.NET page that generates a document for the user based on parameters in the URL. At the bottom of the document is a button that says "Download to PDF".
To implement that feature, I am using ABCPdf. I just feed my web page to the library and it spits out a PDF, and it works very well. Almost TOO well in fact - because the PDF includes the "Download" button itself. How can I include my entire page EXCEPT that specific button?
Here is what I have tried:
In the AddImageToURL call, I added a parameter "&pdfmode" to the URL. Then in my page load, I check for that parameter. If it is there, I say "btnDownloadPDF.Visible=False". This has no effect. I tried a similar approach by checking the page.request.form arguments to detect whether the page is posting back because of a click of the button.
'This does not work; the PDF still includes the download button
Dim pbcontrol = GetPostBackControl(Page)
Dim pdfMode As Boolean =
(pbcontrol IsNot Nothing AndAlso pbcontrol.ID = "btnDownloadPDF") _
OrElse (Not String.IsNullOrEmpty(Context.Request.QueryString("pdfmode")))
If pdfMode Then
btnDownloadPDF.Visible = False
End If
Hum, we probably need some details of how, and when the page is sent to that PDF system.
I suspect that that system takes the page URL and re-loads it?
Or does some code feed the PDF system a existing page class in code?
This suggests?
Hence on your existing page, you need a session() value, (or hidden field) and you have to set that persisted value to "hide" the button.
Then in your on-page load event, check for that session() value, and simple go mybutton.visible = false. So, that external library probably is feed a page url, and it re-renders the whole page - so in page on-load, you need to hide the button?
It just not clear how you hiding that button, but in your code behind, that may well not suffice, since the PDF library is re-loading its OWN copy of the page - hence you need code in the on-load event to hide the button.

Detect when response.redirect has finished?

I have a form that dynamically generates a PDF based on database data. But I don't want to navigate away from the form whilst the PDF is generated and downloaded. So I am using response.redirect to call the .aspx page that generates the PDF and serves it via stream (Have done for many years) so there may be a better option out there now. However I have found people are logging out before the PDF has been sent to the browser which is causing issues.
Is there a way to detect when the reponse.redirect has finished and the file has been downloaded?
I have tried using postmessage and a listener but this doesn't work.
I've also tried setting up and EndRequestHandler as below in my main form:
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler) ;
But this hasn't worked either. The browser is aware as as the tab with the main form has a progress icon in, so there must be a way to intercept the complete event.
Might not be accurate like you want it but I do something sort of similar. When the button is clicked, a "Please Wait..." message appear until the file is ready to be downloaded. The way I do it is the client wait for a cookie. When the server is ready to send the file (after processing) it sets a cookie. Even if the cookie was set in a different request, the client still gets the updated value.

ASP.net serving PDF files in browser - issue with browser history

I'm using the following code to serve a PDF file to the browser:
HttpContext.Current.Response.ContentType = "Application/pdf";
string filename = "somefilename.pdf";
HttpContext.Current.Response.AddHeader("Content-Disposition",
"inline; filename=thefile.pdf");
HttpContext.Current.Response.WriteFile(filename);
HttpContext.Current.Response.End();
When this code fires, the URL doesn't change - it simply serves the PDF file.
In non-IE browsers, when I hit back, it goes back to the page that fired the action. However, in IE, I go back to the PREVIOUS page (i.e. the login page, not the page that serves the PDF files.
Just wondering what the best way to handle this so that IE users can click their browser's "back" button and getting a predictable response.
Hi i think you have to use a button to redirect to other webform and in load page copy your code to charge the information that u want to show in pdf and obviously too the code to show this like pdf
Try the history in the Scriptmanager control.
ASP.NET history

Download report with page update Asp.net

I have a situation where admin deactivates other user's account in web site, this action result in hiding of some control, updating some data in database. Deactivation also result in generation of couple of reports, one has to be save on a predefined location, other has to be downloaded. As much I know we can have only one type of response from server at a time, ie. either page update (html) or excel download, so I perform my UI and database updates on Deactivation and register a javascript function by ScriptManager RegisterStartupScript to open a modal dialog for Report Page. On load of Report Page, I generate a excel, save it on predefined location, generate other excel and send in response.
Questions
Is there any better approach to do this?
My Deactivation page hungs up until excel is download, which should not happen,as I am downling page through Report page.
Some times I have to show user messages like "Save complete", "Deactivation done" which I am doing by registring function by ScriptManager. RegisterStartupScript and then show jquery dialog. Please suggest any better approach.

Doing a ajax / json add to database, and have a "wait doing operation" icon

I got a part on my page I want to improve. It's a file upload that users can add their contacts from files like excel, csv & outlook. I read the contacts and place them in the database, so what I would like to do is to have a regular icon that spins while that operation is doing that, how could I do that? Ajax? I don't want progress bar for the file upload but the operation for reading the file
EDIT: I want to know how to make this work with the add to database using ajax. like should I use a updatepanel? how I could combine a ajax callback with the spinning icon
Thanks
You can generate your own spinning icon on www.ajaxload.info. If you combine it with the jQuery BlockUI plugin, you can display your own modal wait screen.
Spin a GIF.
http://www.ajaxload.info/
If you are using the asp:fileupload, there is a couple things that you can do.
Take advantage of the fact that the asp:fileupload takes a bit of time to upload the file and that is also performs a post-back.
1) put a client-side onclick event for the 'upload' button that will display your spinny graphic and give a message saying 'file being parsed and added to database'.
2) put the server-side onclick event for the 'upload' button that will upload the file, parse it and insert records into the database.
3) when the server-side onclick finishes, the remainder of the page lifecycle occurs and the user gets a fresh page returned to them. And when the browser receives the new page, the spinny graphic will no longer be visible.
This won't allow you to change the message during the upload, but it is quick and easy.
The alternative would be to look at jquery and do some ajax calls.

Resources