Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used
ASP.NET
<asp:UpdatePanel ID="UpdatePanel1" runat="server" 
UpdateMode="Conditional" ChildrenAsTriggers="true">
 <contenttemplate>

 <asp:AsyncFileUpload ID="abcd1" runat="server" Height="25px" Width="242px" OnClientUploadComplete="uploadComplete"
  ThrobberID="imgLoader" OnClientUploadStarted="uploadStarted" 
OnClientUploadError="uploadError"  />

   <asp:Button ID="btnUpload" runat="server" Text="Upload" 
onclick="btnUpload_Click1" />
  </contenttemplate>
                                                                                      
                                                                                
  <triggers>                                                                           
    <asp:PostBackTrigger ControlID="btnUpload" />
   </triggers>
   
    </div>


Client side code:

JavaScript
<script type="text/javascript" language="javascript">

       function uploadError(sender, args) {
           document.getElementById('lblStatus').innerText = args.get_fileName(),
	             "<span style="color:red;">" + args.get_errorMessage() + "</span>";
       }

       function StartUpload(sender, args) {
           document.getElementById('lblStatus').innerText = 'Uploading Started.';
       }

       function UploadComplete(sender, args) {
           var filename = args.get_fileName();
           var contentType = args.get_contentType();
           var text = "Size of " + filename + " is " + args.get_length() + " bytes";
           if (contentType.length > 0) {
               text += " and content type is '" + contentType + "'.";
           }
           document.getElementById('lblStatus').innerText = text;
       }

   </script>


Server side code:
C#
protected void btnUpload_Click1(object sender, EventArgs e)
{
try
{
    HttpFileCollection uploadFiles = Request.Files;
    for (int i = 0; i < uploadFiles.Count; i++)
    {
        HttpPostedFile uploadFile = uploadFiles[i];
        string fileName = Path.GetFileName(uploadFile.FileName);
        if (fileName.Trim().Length > 0)
        {
            uploadFile.SaveAs(Server.MapPath("~/Files/") + fileName);
               lblStatus.Text = "File Uploaded Successfully";
        }
    }
}
catch (Exception ex)
{
     lblStatus.Text = "Error in uploading file";
}

}


how to avoid all page poastback when I click on button?
I dont use the onuploadedcomplete event
Posted
v4

Use
ASP.NET
<triggers>                                                                           
    <asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" />
   </triggers>


Above code instead of your code

ASP.NET
<triggers>                                                                           
    <asp:PostBackTrigger ControlID="btnUpload" />
   </triggers>
 
Share this answer
 
<triggers>
<asp:postbacktrigger controlid="btnUpload" xmlns:asp="#unknown">
Thanks
I use it but this is also not working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900