You can use the onchange event of the fileupload control
JavaScript Fileupload Object : onchange Event handlers - w3resource[
^]
It's not going to work for what you want to do though. The file you have selected can't be "remembered" between postbacks so if you click a button programatically, or do anything else to send the file to the server like submit the form, then your code will check the file extension but when the page returns the file control will be empty again and there is nothing you can do about that.
So if you want to check the file's extension before you upload you need to do it via javascript. You still need your server-code as well though as malicious people can bypass your javascript.
There are various of doing that if you google but here are some
Validate file upload with html5 file api – BinaryTides[
^]
Check File Size & Extension Before Uploading Using jQuery | All PHP Tricks[
^]