【发布时间】:2014-07-08 13:39:26
【问题描述】:
我创建了一个 WebControl。上传文件的按钮在哪里。
我创建 Button 和 FileUpload 之类的
private readonly Button button;
public DocumentUploadButton() {
button = new Button();
button.Click += this.ProcessClick;
var panel = new Panel();
panel.Controls.Add(button);
var fileUpload = new FileUpload();
fileUpload.ID = "fileUploadHidden";
fileUpload.Attributes["style"] = "display:none";
panel.Controls.Add(fileUpload);
Controls.Add(panel);
}
private void ProcessClick(object sender, EventArgs e) {
if (this.fileUpload.PostedFile != null && string.IsNullOrEmpty(this.fileUpload.PostedFile.FileName)) {
// Upload file and handle it like ...
this.fileUpload.SaveAs(....)
}
}
在 OnLoad 中我附加了一个 JavaScript 函数:
protected override void OnLoad(EventArgs e) {
this.button.Attributes.Add("onclick", "document.getElementById('fileUploadHidden').click();");
base.OnLoad(e);
}
现在,当用户单击按钮时,将调用 FileUpload 并显示 FileChooseDialog。这很好用。但在此之后,Click-Handler ProcessFile() 未在某些客户机器上执行(我认为 PostBack 未执行)。在我的开发者机器上,这工作正常。
谁能帮帮我,客户机器出了什么问题?
我们使用 InternetExplorer。
【问题讨论】:
标签: c# javascript asp.net file-upload