简体   繁体   中英

Select only one onchange event of Fileupload

I have an asp.net page with master page. I have a fileupload control on child(having master page) page. I am using jquery's change event for fileupload on child page. now i want to disable fileupload control for some reasons from master page. so i am using this script.

 function blockFileUpload() {
                $('input[type=file]').change(function () {
                    $('input[type=file]').val('');
                    alert("You Can Not Upload File. Files Storage (50 MB) Limit Reached. ");
                    $('input[type=file]').preventDefault();
                    return false;
                });
            }

Now when file upload change event is called both event work simultaneously. so how can i disable child page's change event and hook only master page's onchange event.

Thanx in advance...

Unbind all your change events first and then assign your new change event. For eg:

function blockFileUpload() {
                $('input[type=file]').unbind('change');
                $('input[type=file]').change(function () {
                    $('input[type=file]').val('');
                    alert("You Can Not Upload File. Files Storage (50 MB) Limit Reached. ");
                    $('input[type=file]').preventDefault();
                    return false;
                });
            }

The code $('input[type=file]').unbind('change'); unbinds all the change event related to the file inputs.

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