views:

8

answers:

1

I have just written a Word Document creation web application using .NET 3.5 which uses XML from a SQL backend and XSL-T stylesheets to transform word xml documents as templates into letters for users to send to clients. Everything is working well and I'm pleased with the result, xslcompiledtransform is super fast even with bloated word xml documents :0) . The only problem I have is that this application is launched in a modal IE dialog from an older .NET 1.1 application and the client wants the user to be conditionally prompted before closing of the modal dialog.

Once the user has invoked the generation process a partial post back event is fired and the list of documents is displayed in a list view in an update panel, when they click on the name of a document the document is served to them and IE shows the download dialog and another partial postback updates the listview with a green tick to indicate the user has requested that document.

The client requested that if the user attempted to close the dialog before all the documents are requested then the user is prompted with a confirm option of OK and Cancel.I implemented this fine with an actual "Close" button on the form which shows a conform popup and if the user clicks OK then the window is closed with a javascript hack. The problem comes if the user decides to click the standard window x button. I managed to use the IE approach of adding the onunload event to the body and returning a string with a custom message like Microsoft CRM uses but this no where near ideal for a couple of reasons.

Firstly it is ugly as hell and I don't like the standard uncontrollable additional message that comes with this functionality. Also the main problem I have is that this is being caused with every partial post back which is understandable but bloody annoying and even if no documents have been generated or they have and all have been requested.

So finally my question is: Can I either ideally somehow trick IE into cancelling the closure in onunload with using the standard javascript confirm using my own function containing the simple logic, maybe with an Iframe or such like? Or add some logic to when the standard IE popup appears?

I know this is standard functionality and it's there for a good security reason but it is what the client really wants and this is not a public facing site, it is only used internally within their company.

Many Thanks in advance and sorry for the waffle but just wanted to make sure I gave as much details as possible because I antipicated the initial questions of "Why?".

Paul

A: 

With the release looming and nobody prepared to sift through my waffle I went with the standard IE onbeforeunload event. In my js i had:

window.onbeforeunload = PromptUserToClose

function PromptUserToClose()
  if(!allDownloaded){
     return "Are you sure....."
  }

The problem though was I had LinkButtons in my update panel which were causing PartialPost backs which IE for some reason beleived was an unload of the window so to get around it I changed them to asp:Hyperlinks and then added a javascript postback call from server side using Page.ClientScript.GetPostBackEventReference(Me, "MyCustomArgument"). This did the job.

Thanks

Paul

Paulie Waulie