0

母版页表单标签:

    <form runat="server" enctype="multipart/form-data" method="post">

文件上传.aspx

 <asp:UpdatePanel runat="server" ID="upnlFileUpload">     
  <ContentTemplate> 
  <asp:Button ID="Save" runat="server" Text="Save" 
        style="margin-left: 0px" Width="350px" onclick="Save_Click" />
    <ajaxToolkit:AsyncFileUpload
        ID="AsyncFileUpload1" runat="server" 
        onuploadedcomplete="AsyncFileUpload1_UploadedComplete" />
  </ContentTemplate>
  </asp:UpdatePanel>    

文件上传.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           btnSave.Enabled = false;
        }
    }

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        btnSave.Enabled = true;
    }

如果我上传文件,则 UploadedComplete 会被触发(我通过将文件保存在临时位置来测试它),但“保存”按钮未启用。甚至断点也能下线:

btnSave.Enabled = true;

这段代码有什么问题?!

4

1 回答 1

1

你需要做一点调整。

这是您需要做的使按钮禁用的操作:

在你<head>的标签中:

<script type = "text/javascript">
        function ClientUploadComplete(sender, e) {
            var btnSave = document.getElementById("<%=btnSave.ClientID %>");
            btnSave.disabled = true;
            btnSave.value = "Save";
        }
</script>

在您的<body>标签中:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>先加后加:

 <asp:UpdatePanel runat="server" ID="upnlFileUpload">     
  <ContentTemplate> 
   <asp:AsyncFileUpload ID = "AsyncFileUpload1" runat = "server" OnClientUploadStarted = "" OnClientUploadComplete = "ClientUploadComplete" />
    <asp:Button ID="btnSave" runat="server" Text="Save" />
  </ContentTemplate>
  </asp:UpdatePanel>    
于 2012-04-05T13:18:53.033 回答