Down Loading a FileLast Updated: 5/6/2009 | |
| Sections above here: Home » Development » Javascript | |
|
Sections below here: Topics in this section: |
How to prevent locked forms after sending a file with IntraWebWhen you send a file via WebApplication.SendFile(), then your form may be locked, thus unusable, after the file has been received. This articel explains the reason and how to avoid that. Sending files with IntraWeb is very easy. Just place a button on
procedure TIWForm7.ButtonSendClick(Sender: The first parameter is the location of the file (do not use relative paths, esp. when running as ISAPI), the second one tells to send the file as “attachment”. This will open a file dialog at the user’s browser: The user now has the choice to save the file or to directly fire up the associated application (Excel in this example). After that the current form of your application will re-appear. Easy and works great! There is a catch though:After returning to the form your user won’t be able to click on any control - the form is “dead”, it does not accept any user input anymore. If you read through the docs or the FAQ (yes there is one ;-), you will find a hint, that SendFile (and SendStream) do not work with LockOnSubmit. So you just have to set LockOnSubmit to false on every form where you are going to send a file. Easy! This solution is annoying?Yes, of course it is! Why do you have to disable some useless option, on every form? Why can’t IntraWeb just do that for you automatically? To understand Click Happy UsersClick Happy Users are those who are impatient and start clicking into Web forms while the form still loads or when it just submits back to the server. This may produce unexpected errors, such as session timeouts. The user is in the middle of something and just because he was a little too impatient, he might loose his session in the worst case. This is very uncomfortable and something you don’t expect from applications - even if they are running on the web. To handle both situations IntraWeb activates an invisible “Lock” right when you click on any button on your form (LockOnSubmit), and this Lock will be disabled when the response finished rendering (LockUntilLoaded). This is very When you send a file via WebApplication.SendFile(), then the Lock does not get unlocked after the file has be received unfortunately. This is because the browser does not fire any JavaScript event after the file has been received, Turning off this locking is not really an option because you will all this “happy click” prevention. The real solutionThe solution is simple, but effective. Attach the following lines to the button’s ScriptEvents property (only for buttons/links which are used for sending files): ReleaseLock(); Please note that when using TMSs components the "ClientEvent" property is the equivalent to ScriptEvents. When using TMS's components the script syntax for the locking problem is as follows, where "BTNEXPORT" is the name given to the button in question: SubmitClickConfirm('BTNEXPORT','', true, ''); This is JavaScript code which will get executed before your button submits back to the server and fires the Delphi OnClick event. It will turn off the lock only for this button, which will make your form respond as expected after the file has been received. Don’t forget the final “return true;” - if you omit that, then your Delphi OnClick won’t be fired. |
(C) 2002-2009 - Atozed Software Ltd. | |