在使用ajax时,asp.net按钮控件单击事件无法正常工作

时间:2016-10-04 14:19:33

标签: c# asp.net asp.net-ajax

我在asp.net C#中使用Ajax。我要做的是,点击链接后,应显示divdiv包含文件上传控件和名为“上传文件”的按钮。单击上载文件按钮时,它正在检查是否有任何文件上载控件具有文件。如果是,它会将文件上传到某个目录并更新标签以显示上传了多少个文件0或更多。这是截图解释: Link (Insert More Attachments is clicked then file upload controls are visible and even after I select the files, button always displays message 0 file(s) uploaded)

这是代码片段,我正在使用Ajax和asp.net C#

<div class="form-group row">
 <asp:UpdatePanel runat="server" id="UpdatePanel1" updatemode="Conditional">           
            <ContentTemplate>
                    <div class="col-xs-5">
                    <% if (Session["MemberID"]!= null)
                       {%>                   
                       <asp:LinkButton ID="insertMore" runat="server" OnClick="insertMoreclicked">(Insert More Attachments)</asp:LinkButton>
                      <%} %>

                </div><br />

                <div id="moreUploadsDiv" runat="server" visible="false">
                <br />
                <asp:FileUpload ID="moreUpload1" runat="server" />
                <asp:FileUpload ID="moreUpload2" runat="server" />
                <asp:FileUpload ID="moreUpload3" runat="server" />
                <asp:FileUpload ID="moreUpload4" runat="server" />

                <asp:Button ID="uploadMoreFilesBtn" runat="server" Text="Upload" OnClick ="uploadMoreClicked" CausesValidation="false" />
                <br />
                <asp:Label ID="uploadInfoLbl" runat="server" Text=""></asp:Label>

             </ContentTemplate>
</asp:UpdatePanel>

这是按钮的文件事件背后的代码:

protected void uploadMoreClicked(object sender, EventArgs e)
{
     int countFiles = 0;
     if (moreUpload1.HasFile)
     {
         moreUpload1.PostedFile.SaveAs(Server.MapPath("/Upload/") + moreUpload1.FileName);
         string fn2 = moreUpload1.FileName;
         bool status2 = blReg.insertFiles(fn2, FileID);

         countFiles++;
     }
     if (moreUpload2.HasFile)
     {
         moreUpload2.PostedFile.SaveAs(Server.MapPath("/Upload/") + moreUpload2.FileName);
         string fn2 = moreUpload2.FileName;
         bool status2 = blReg.insertFiles(fn2, FileID);

         countFiles++;
     }
     if (moreUpload3.HasFile)
     {
         moreUpload3.PostedFile.SaveAs(Server.MapPath("/Upload/") + moreUpload3.FileName);
         string fn2 = moreUpload3.FileName;
         bool status2 = blReg.insertFiles(fn2, FileID);

         countFiles++;
     }
     if (moreUpload4.HasFile)
     {
         moreUpload4.PostedFile.SaveAs(Server.MapPath("/Upload/") + moreUpload4.FileName);
         string fn2 = moreUpload4.FileName;
         bool status2 = blReg.insertFiles(fn2, FileID);

         countFiles++;
     }
     uploadInfoLbl.Text = countFiles + " file(s) uploaded<br/>";
}

但按钮点击事件不起作用。请告诉我我做错了什么。在此先感谢!

0 个答案:

没有答案