简体   繁体   中英

How to trigger OnCommandClick first than OnClientClick

I am creating a session inside the OnCommandClick to save information about a file that will be downloaded. If I click to download it, the OnClientClick works fine and I can download the file.

But when I have a grid with more than one file, I think that the function OnClientClick is being fired first than OnCommandClick , so the session is being updated after the download, so I always get the wrong file. Just when I click again at the same file is that the correct one comes (because probably the session was updated after the first click).

For example: files 1, 2, 3 and 4... if I click at file 1, it downloads ok, but when I click at file 2, it downloads the file 1 again, then if I click in file 4, it downloads the file 2, if I click 3, it downloads file 4, always the previous one.

Can I force the OnCommandCLick to run first than OnClientClick to try to solve this problem?

OnClientClick always gets called first. I suggest getting rid of OnClientClick and move the file download code to the server-side event OnCommandClick , right after updating the session.

You can either use FileStream or inject a javascript code that will start the file download.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM