1

单击asp:FileUpload按钮时是否可以触发OnClick事件?

4

2 回答 2

1

根据w3schools,文件类型的输入可以支持所有标准事件。所以你可以做的是给你的控件写一个点击的javascript事件:

YOURCONTROL.Attributes.Add("onclick","YourLogic");
于 2012-11-06T08:31:45.257 回答
1

您可以使用闪存代码,它将文件上传器作为可点击的按钮。但为此,您需要下载 swfupload.swf 文件。

    <input type="file" id="uplaodExcel" name="uplaodExcel" />

以下是javascript代码:

Sys.Application.add_init(function () {
    HideError();
    $("#uplaodExcel").makeAsyncUploader({
        upload_url: 'EventName',//Event you want to occur on click
        flash_url: '../Scripts/swfupload.swf',//flash file path that you download
        button_image_url: '@Url.Content("~/Content/blankButton.png")',// for button style
        file_size_limit: "10MB",
        file_types: "*.XLS; *.xlsx", //File extension you can provide any
        disableDuringUpload: 'INPUT[type="submit"]',
        upload_success_handler: function (file, server_data, receivedResponse) {
            var data = "";
            try {
                // you can add your code here
            } catch (e) { }

        }
    });
});
于 2012-11-06T13:47:26.673 回答