Ajax Uploader - Uploader_FileUploaded server event not firing

  •  06-16-2011, 7:57 AM

    Ajax Uploader - Uploader_FileUploaded server event not firing

    Hello,
     
    I am using an ajax uploader control and setting the manual start upload to true.  My exact code is below.  When I use this code on a page that does not have any Jquery ajax calls everything works fine and the file that I select for upload gets uploaded to my C drive when my submit button is clicked.  If I use the same code within a page that makes Jquery ajax calls, the 
    Uploader_FileUploaded event is never hit, the progress bar turns green and it looks like it uploads the file that I selected for upload when the submit button is clicked but the file does not end up in my C drive.  It is probably being uploaded to some default temporary location which I don't know or it is not actually getting uploaded.  Any reason why the 
    Uploader_FileUploaded event would not get fired on a page that uses Jquery Ajax and would get fired on a page that does not have any Jquery ajax calls? Also, by default where does the Ajax uploader control upload files if I don't specify a different directory in the 
    Uploader_FileUploaded event?
     
     
    Thank you. 
     
     
     
    <script runat="server">
        'Private Sub InsertMsg(ByVal msg As String)
        '    ListBoxEvents.Items.Insert(0, msg)
        '    ListBoxEvents.SelectedIndex = 0
        'End Sub
        Private Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            'InsertMsg("You clicked the Submit Button.")
            'InsertMsg("You have uploaded " & uploadcount & "/" & Uploader1.Items.Count & " files.")
        End Sub
        Private uploadcount As Integer = 0
        Private Sub
    <script runat="server">
        'Private Sub InsertMsg(ByVal msg As String)
        '    ListBoxEvents.Items.Insert(0, msg)
        '    ListBoxEvents.SelectedIndex = 0
        'End Sub
        Private Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            'InsertMsg("You clicked the Submit Button.")
            'InsertMsg("You have uploaded " & uploadcount & "/" & Uploader1.Items.Count & " files.")
        End Sub
        Private uploadcount As Integer = 0
        Private Sub Uploader_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs)
            uploadcount += 1
            'InsertMsg("File uploaded! " & args.FileName & ", " & args.FileSize & " bytes.")
        
            'Copys the uploaded file to a new location. 
            
            args.CopyTo("C:\\" & Date.Now.ToShortDateString().Replace("/", "") + ".pdf")
            'You can also open the uploaded file's data stream. 
            'System.IO.Stream data = args.OpenStream(); 
        End Sub
        Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs)
            'SubmitButton.Attributes("itemcount") = Uploader1.Items.Count.ToString()
        
            MyBase.OnPreRender(e)
        End Sub
    </script>
    <!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <a href="DefaultPage.aspx" target="_blank">Launch CFN Workflow tool</a><br /><br />
        <a href="GetCaseResults.aspx" target="_blank">Launch Results Directly</a>
        </div>
        <div>
         <%--<CuteWebUI:UploadAttachments runat="server" ID="Uploader">                
             </CuteWebUI:UploadAttachments>--%>
        </div>
           <div id="divNCO" runat="server" class="Collapse">
        <%--<input id="cancelUpload" value="Cancel this upload" onclick="cancel_upload()" />--%>
        <table>
            <tr>
                <td colspan="2" align="left"><textarea id="txtArea" cols="50" rows="10"></textarea></td>
            </tr>
            <tr>
                <td colspan="2" align="left"><asp:RadioButtonList ID="rblNCO" runat='server' CssClass="rblNCO" RepeatDirection="Horizontal">
                    <asp:ListItem Value="0" Text="Case owner can now resolve this case"></asp:ListItem>
                    <asp:ListItem Value="1" Text="This is a comment/question"></asp:ListItem>
                </asp:RadioButtonList></td>
    </tr>
            <tr>
                <td align="left"><CuteWebUI:UploadAttachments runat="server" ID="Uploader1" ManualStartUpload="true" MaxFilesLimit="3" MaxFilesLimitMsg="You can only upload 3 files at a time" ValidateOption-AllowedFileExtensions="pdf, tif" InsertText="Attach Files" InsertButtonStyle-CssClass="float:left;" OnFileUploaded="Uploader_FileUploaded">                               
             </CuteWebUI:UploadAttachments></td>
             <td valign="top">            
                <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"
                    Text="Submit" OnClick="SubmitButton_Click" />
                <asp:Button ID="btnCancelNCODiv" runat="server" text="Cancel" CssClass="FloatRight" />
             </td>
            </tr>        
        </table>    
            
        </div>
        </form>
    </body>
    </html>
    <script type="text/javascript">
        function submitbutton_click() {
            var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');
            var uploadobj = document.getElementById('<%=Uploader1.ClientID %>');
            if (!window.filesuploaded) {
                if (uploadobj.getqueuecount() > 0) {
                    alert("starting upload");
                    uploadobj.startupload();
                    alert("done upload");
                }
                else {
                    var uploadedcount = parseInt(submitbutton.getAttribute("itemcount")) || 0;
                    if (uploadedcount > 0) {
                        return true;
                    }
                    alert("Please browse files for upload");
                }
                return false;
            }
            window.filesuploaded = false;
            return true;
        }
        function CuteWebUI_AjaxUploader_OnPostback() {
            window.filesuploaded = true;
            var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');
            var tmp = '<%=SubmitButton.ClientID %>';
            alert('id = ' + tmp);
            submitbutton.click();
            return false;
        }
    //    function CuteWebUI_AjaxUploader_OnSelect(files) {
    //        alert("CuteWebUI_AjaxUploader_OnSelect");
    //    }
                </script>
    (ByVal sender As Object, ByVal args As UploaderEventArgs)
            uploadcount += 1
            'InsertMsg("File uploaded! " & args.FileName & ", " & args.FileSize & " bytes.")
        
            'Copys the uploaded file to a new location. 
            
            args.CopyTo("C:\\" & Date.Now.ToShortDateString().Replace("/", "") + ".pdf")
            'You can also open the uploaded file's data stream. 
            'System.IO.Stream data = args.OpenStream(); 
        End Sub
        Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs)
            'SubmitButton.Attributes("itemcount") = Uploader1.Items.Count.ToString()
        
            MyBase.OnPreRender(e)
        End Sub
    </script>
    <!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <a href="DefaultPage.aspx" target="_blank">Launch CFN Workflow tool</a><br /><br />
        <a href="GetCaseResults.aspx" target="_blank">Launch Results Directly</a>
        </div>
        <div>
         <%--<CuteWebUI:UploadAttachments runat="server" ID="Uploader">                
             </CuteWebUI:UploadAttachments>--%>
        </div>
           <div id="divNCO" runat="server" class="Collapse">
        <%--<input id="cancelUpload" value="Cancel this upload" onclick="cancel_upload()" />--%>
        <table>
            <tr>
                <td colspan="2" align="left"><textarea id="txtArea" cols="50" rows="10"></textarea></td>
            </tr>
            <tr>
                <td colspan="2" align="left"><asp:RadioButtonList ID="rblNCO" runat='server' CssClass="rblNCO" RepeatDirection="Horizontal">
                    <asp:ListItem Value="0" Text="Case owner can now resolve this case"></asp:ListItem>
                    <asp:ListItem Value="1" Text="This is a comment/question"></asp:ListItem>
                </asp:RadioButtonList></td>
    </tr>
            <tr>
                <td align="left"><CuteWebUI:UploadAttachments runat="server" ID="Uploader1" ManualStartUpload="true" MaxFilesLimit="3" MaxFilesLimitMsg="You can only upload 3 files at a time" ValidateOption-AllowedFileExtensions="pdf, tif" InsertText="Attach Files" InsertButtonStyle-CssClass="float:left;" OnFileUploaded="Uploader_FileUploaded">                               
             </CuteWebUI:UploadAttachments></td>
             <td valign="top">            
                <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"
                    Text="Submit" OnClick="SubmitButton_Click" />
                <asp:Button ID="btnCancelNCODiv" runat="server" text="Cancel" CssClass="FloatRight" />
             </td>
            </tr>        
        </table>    
            
        </div>
        </form>
    </body>
    </html>
    <script type="text/javascript">
        function submitbutton_click() {
            var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');
            var uploadobj = document.getElementById('<%=Uploader1.ClientID %>');
            if (!window.filesuploaded) {
                if (uploadobj.getqueuecount() > 0) {
                    alert("starting upload");
                    uploadobj.startupload();
                    alert("done upload");
                }
                else {
                    var uploadedcount = parseInt(submitbutton.getAttribute("itemcount")) || 0;
                    if (uploadedcount > 0) {
                        return true;
                    }
                    alert("Please browse files for upload");
                }
                return false;
            }
            window.filesuploaded = false;
            return true;
        }
        function CuteWebUI_AjaxUploader_OnPostback() {
            window.filesuploaded = true;
            var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');
            var tmp = '<%=SubmitButton.ClientID %>';
            alert('id = ' + tmp);
            submitbutton.click();
            return false;
        }
    //    function CuteWebUI_AjaxUploader_OnSelect(files) {
    //        alert("CuteWebUI_AjaxUploader_OnSelect");
    //    }
                </script> 
View Complete Thread