Click here to Skip to main content
16,009,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
file uploader ajax controls "OnClientUploadError" event is not working,...file uploder is not showing error message when file is not uploaded .
ASP.NET
<form id="form1"  runat="server">
    <div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:Button ID="btnUpload" runat="server" 
            Text="Upload File" onclick="btnUpload_Click"/>
            
<asp:ModalPopupExtender runat="server" 
                        ID="modelPopupExtender1" 
                        TargetControlID="btnUpload"
                        PopupControlID="popUpPanel" 
                        OkControlID="btOK" 
                        BackgroundCssClass="modalBackground">


 <asp:Panel ID="popUpPanel" runat="server" CssClass="pnl">
<!-- Problem appears to be in the next block --> 
 <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" 
                     OnUploadComplete="UploadComplete" 
                     OnClientUploadComplete="Success" 
                     OnClientUploadError="Error" 
                     ThrobberID="loader" Width="400px"/>
 <asp:Image ID="loader" runat="server" 
            ImageUrl ="~/loading.gif" 
            Style="display:None"/>
<!-- End of suspected problem block -->
 <asp:Label ID="lblMessage" runat="server"/><br /><br />
 <asp:Button ID="btOK" runat="server" Text="OK" />
 <asp:LinkButton ID="LinkButton1" runat="server" CssClass="close" 
 OnClientClick="$find('modelPopupExtender1').hide(); return false;"/>

</contenttemplate>

    
    </div>
    <br /><br />
    
    </form>
Posted
Updated 6-Jan-13 22:04pm
v3
Comments
Prasaad SJ 17-Dec-13 0:10am    
Hi RaheMani,
The code which you have given in the top is working fine for me. It is going to the error script once the error is occurred. Can you describe in detail about the error or scenario you r looking for. ?

Hi.

The behavior of "AjaxFileUpload" is different from "AsyncFileUpload" which also has its own bugs: for some developers these errors are triggered and not for others. And the source code of AjaxControlToolbox, not help because the files and start down with mistakes to go adjusting. In my case, when I required to develop professional applications, you can not expect the stability of the AjaxControlToolkit. We understand that developers of AjaxControlToolkit have made ​​a great effort, but I think it is not enough to trust and include it in production applications.


With asp:AjaxFileUpload the OnClientUploadError not fired. I have similar bug.

Test this example:

The code validate the size of file onClient. When Size > 1000000 fire exception. The exception not fired OnClientUploadError="uploadError" and the file was upload to the server.

I need to validate de size of file onCliente to prevent the fileupload on the server (including temporary file uploaded to the server)

JavaScript
<script type="text/javascript">


    function uploadError(sender, args) {
        //Good practice to put try,catch block. it will avoid javascript error at window status.
            var ArchivoNombre = args.get_fileName();
            var MensajeError = args.get_errorMessage();
            var Mensaje = "Archivo no cargado: " + ArchivoNombre + " / ERROR..." + MensajeError;

            //Desarrollar algún proceso en el servidor: grabar en base de datos, etc.
            //  En este caso, se crea una variable de sesión.
            //PageMethods.RegisterUploadError(MensajeError, Mensaje, OnSucceeded, OnFailed);
        }
    }

    function uploadComplete(sender, e) {

        var Peso = context.get_fileSize();
        var ArchivoNombre = context.get_fileName();

        /*Validation for file size*/
        if (parseInt(Peso) > 1000000) {

            var Mensaje = "Archivo excede el tamaño límite de 2 Mb. Archivo : " + ArchivoNombre + " Peso(bytes): " + Peso;
            var displayElement = document.getElementById("ResultId");
            displayElement.innerHTML = Mensaje;

            var err = new Error();
            err.name = 'Error Uploading';
            err.message = 'Excedió el límite.';
            throw (err);

        }
        else {

          //Etc...


        }
    }
</script>



Some HTML:

ASP.NET
<body>
    <form id="form1" runat="server">
    <div>
        <asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server" xmlns:asp="#unknown">
        </asp:toolkitscriptmanager>
        
        <asp:ajaxfileupload id="AjaxFileUpload1" runat="server" xmlns:asp="#unknown">
        OnClientUploadComplete="uploadComplete" 
        OnClientUploadError="uploadError" 
        onuploadcomplete="AjaxFileUpload1_UploadComplete" />

        <div id="testuploaded" style="display: none; padding: 4px; border: gray 1px solid;">
            <h4>
                list of uploaded files:</h4>
            <hr />
            <div id="fileList">
            </div>
        </div>

    <p>
        <span style="background-color:Aqua" id="ResultId"></span>
    </p>

        <asp:button id="btnSubmit" runat="server" text="Postback" />

    </asp:ajaxfileupload></div>
    </form>
</body>



CodeBehind:

C#
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs file)
   {
       //Grabar en disco
       string rutaUploads = HttpContext.Current.Server.MapPath("Uploads\\");
       string FullNombre = rutaUploads + file.FileName;
       AjaxFileUpload1.SaveAs(FullNombre);

   }
 
Share this answer
 
Here, have a look at exact same issue with solution accepted: AjaxFileUpload "OnClientUploadError" event not firing[^]

It's suggested that as mentioned at knowledgebase article[^], try:

Sample:
ASPX:
XML
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function OnClientUploadComplete() {
            alert("upload complete");
        }
        function showUploadError(sender, args) {
          alert(args.get_errorMessage());
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <asp:AjaxFileUpload ID="AjaxFileUpload1"  AllowedFileTypes="jpg,jpeg"
            runat="server" OnUploadComplete="AjaxFileUpload1_UploadComplete" OnClientUploadError="showUploadError"
            OnClientUploadComplete="OnClientUploadComplete" />
    </div>
    </form>
</body>
</html>

.CS file
C#
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
   {
       string filePath = Request.PhysicalApplicationPath + "UploadedImages\\test.jpg";
       AjaxFileUpload1.SaveAs(filePath);
   }


One more similar issues reported and resolved: AsyncFileUpload problem[^]
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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