0

I am creating an ASP.NET website and I'm using the AJAX Control Toolkit "AsyncFileUpload" control, I just want to pass a value to the onclientuploadcomplete client event, and I want to do that after saving the file from the UploadedComplete server event.

Here's my current AsyncFileUpload:

 <asp:AsyncFileUpload ID="AsyncFileUpload2" runat="server" CssClass="fileupload" onclientuploadstarted="uploadStarted" 
                                UploadingBackColor="#CCFFFF" Width="221px" 
                                onclientuploaderror="upload_error" ClientIDMode="AutoID" 
                                onclientuploadcomplete="done_uploading" />

And her's my current Javascript code:

</script>

<script language="javascript" type="text/javascript">
   
   var baseUrl = "<%= ResolveUrl("~/") %>";

    function done_uploading(THE_VALUE) {
         //TODO: ALERT THE_VALUE
    }

    function uploadStarted(sender, args) {

        var file = args.get_fileName();

        var extensions = "7z";

        if (!new RegExp("(" + extensions + ")$").test(file)) {
            throw (new Error());
        } else {
           // show_loading();
        }
    }

    function upload_error() {

    }

</script>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mohamed Tarek
  • 111
  • 4
  • 11

1 Answers1

0

You can try with this code - Just replace your delegate with this

function upload_error (sender, args)
{
   //Print : args.get_fileName() 

   //Print also :args.get_errorMessage()

   document.getElementById('JustSampleForPrint').innerText = args.get_errorMessage();
}

Nota : Add this element JustSampleForPrint, in order to print inside.

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
  • How about custom data, to pass it from the server event to the client event? Is it possible? – Mohamed Tarek Sep 27 '12 at 15:40
  • I suggest you to modify your sign of method, in order to capture error. it's possible but it's not adapted in this case, you can modify your html render with c# with <% %> tag, or generate js script with RegisterStartup ... – Aghilas Yakoub Sep 27 '12 at 15:44
  • Hi Aghilias, Actually I tried before to modify a hidden field from the server event and retrieve its value from the client event later, but the hidden field is always null, I will try now RegisteStartup to see if it would works on a normal HTML element. Thank you. – Mohamed Tarek Sep 27 '12 at 15:51
  • @Mohamed You can use this : <% YourFunctionWhoReturnValue() %> in your value of control – Aghilas Yakoub Sep 27 '12 at 15:54