【发布时间】:2015-09-01 10:58:23
【问题描述】:
我有这样的文件上传:
<asp:FileUpload id="FileUploadControl" runat="server" />
<asp:Button runat="server" id="UploadButton" class="btn btn-default disabled" text="Upload" onclick="UploadButton_Click" />
<br /><br />
<asp:Label runat="server" id="StatusLabel" text="Upload status: " />
以及背后的代码:
protected void UploadButton_Click(object sender, EventArgs e)
{
if(FileUploadControl.HasFile)
{
try
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
}
catch(Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
我想要检查 fileupload 是否有文件并激活我的按钮 UploadButton...确切地将 CSS 类更改为 btn btn-default active。如果可能的话,我现在不??
【问题讨论】: