" OnClientUploadError"事件不起作用 [英] "OnClientUploadError" event is not working

查看:63
本文介绍了" OnClientUploadError"事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件上传器ajax控件OnClientUploadError事件无法正常工作,...文件上传器未上传文件时未显示错误消息。

file uploader ajax controls "OnClientUploadError" event is not working,...file uploder is not showing error message when file is not uploaded .

<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>

推荐答案

find('modelPopupExtender1' )。隐藏();返回false; / >

< / contenttemplate >


< / div > ;
< br / > < br / >

< / form >
find('modelPopupExtender1').hide(); return false;"/> </contenttemplate> </div> <br /><br /> </form>


在这里,看一下与solut完全相同的问题离子接受: AjaxFileUploadOnClientUploadError事件未触发 [< a href =http://forums.asp.net/t/1853341.aspx/1?AjaxFileUpload+OnClientUploadError+event+not+firing\"target =_ blanktitle =New Window> ^ ]



建议在知识库文章中提到 [ ^ ],试试:



样本:

ASPX:

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:
<%@ 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文件


.CS file

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





报告并解决了另外一个类似问题:AsyncFileUpload问题 [ ^ ]


您好。



AjaxFileUpload 的行为不同于 AsyncFileUpload ,它也有自己的错误:对于一些开发人员来说,这些错误是触发而不是其他错误。而AjaxControlToolbox的源代码,没有帮助,因为文件和错误开始调整。就我而言,当我需要开发专业应用程序时,您不能指望AjaxControlToolkit的稳定性。我们知道AjaxControlToolkit的开发人员付出了很大的努力,但我认为仅仅信任并将其包含在生产应用程序中是不够的。





使用asp:AjaxFileUpload OnClientUploadError未触发。 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)



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)

<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:






Some HTML:

<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:






CodeBehind:

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);

   }


这篇关于&QUOT; OnClientUploadError&QUOT;事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆