我创建了一个WebControl。在我的构造函数中:
private readonly Button button;
public DocumentUploadButton() {
button = new Button();
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);
}
protected override void OnLoad(EventArgs e) {
this.button.OnClientClick = "InvokeFileUploadScript";
const string csName = "InvokeFileUploadScript";
var csType = GetType();
var script = new StringBuilder();
script.Append("<script type=\"text/javascript\"> function InvokeFileUpload(sender, args) {");
script.Append("document.getElementById('fileUploadHidden').click();");
script.Append("}");
script.Append("</script>");
Page.ClientScript.RegisterClientScriptBlock(csType, csName, script.ToString());
base.OnLoad(e);
}
但是,当我现在点击按钮时,永远不会调用FileUpload。
有人可以帮我解决我做错的事吗? - 谢谢。
答案 0 :(得分:0)
如果您将this.button.OnClientClick = "InvokeFileUploadScript";
替换为this.button.OnClientClick = "InvokeFileUpload";
,是否效果不佳?