单击 asp:FileUpload 按钮是否可以触发OnClick
事件?
答案 0 :(得分:1)
根据w3schools,类型文件的输入可以支持所有标准events。 所以你可以做的是控制点击的javascript事件:
YOURCONTROL.Attributes.Add("onclick","YourLogic");
答案 1 :(得分:1)
你可以使用flash代码将文件上传者作为可点击的按钮。但为此你需要下载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) { }
}
});
});