Change MultipleFilesUpload on-the-fly

Last post 07-01-2011, 7:34 AM by smcleod. 6 replies.
Sort Posts: Previous Next
  •  06-30-2011, 8:44 AM 68280

    Change MultipleFilesUpload on-the-fly

    I have an upload control that is contained in a jQuery UI dialog.... users are allowed to upload multiple new files, or change/update one file at a time. So the control starts off allowing multiple files to be uploaded. But if the user wants to update an already existing file, they need to be restricted to only selecting one file.
     
    I  change the MultipleFilesUpload property in this event, CuteWebUI_AjaxUploader_OnBrowse... but the file dialog still allows the user to select multiple files, granted it only processes one of the selected files and ignores the rest. What do I need to do to get the file dialog to only allow the user to select one file at a time?
     
    Do I need to use two different upload controls? Or is a single upload control able to be used on same screen in varying ways?
     
    Thanks in advance!
  •  06-30-2011, 8:52 AM 68281 in reply to 68280

    Re: Change MultipleFilesUpload on-the-fly

    Hi smcleod,
     
    Please set MultipleFilesUpload="false" and try it again:

    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Uploading multiple files like GMail</title> 
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="content">        
                <br />
                <CuteWebUI:UploadAttachments InsertText="Upload Multiple files Now" runat="server"
                    ID="Attachments1" MultipleFilesUpload="false">
                    <InsertButtonStyle />
                </CuteWebUI:UploadAttachments>
                <br />
                <br />          
                <br />
                <div>
                    Server Trace:
                    <br />
                    <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                </div>
            </div>
        </form>
    </body>
    </html>

    Thanks for asking
  •  06-30-2011, 9:35 AM 68284 in reply to 68281

    Re: Change MultipleFilesUpload on-the-fly

    Now, I have the opposite problem... when user needs to upload multiple files, in the
    OnBrowse event I change
     
    this.internalobject.MultipleFilesUpload = true;
     
     
    And now the dialog won't allow the user to select multiple files.... see event code below
    to show what I'm trying to do...
     
    function CuteWebUI_AjaxUploader_OnBrowse()
    {
        if (_ProjectAttachmentId > 0)
        {
            // We are replacing a single attachment, so only allow one to be selected for upload
            this.internalobject.MultipleFilesUpload = false;
        }
        else
        {
            // We are uploading new attachments, so allow as many as they want
            this.internalobject.MultipleFilesUpload = true;
        }
    }
     
  •  06-30-2011, 10:16 AM 68286 in reply to 68284

    Re: Change MultipleFilesUpload on-the-fly

    Hi smcleod,
     
    Please use server side code to set this:

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

    <script

    runat="server">
        static int i = 0;
        void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }

        void ButtonMultiple_Click(object sender, EventArgs e)
        {
            if(i%2==0)
            {    
                Attachments1.MultipleFilesUpload=true;
            }
            else
            {
                Attachments1.MultipleFilesUpload=false;
            }
            i += 1;
        }
      
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Uploading multiple files</title> 
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="content">                       
                    <div>
                        <CuteWebUI:UploadAttachments runat="server" ID="Attachments1" MultipleFilesUpload=false>
                        </CuteWebUI:UploadAttachments>
                    </div>
                         <br />         
                <asp:Button ID="ButtonMultiple" runat="server" Text="Single/Multiple Files Upload Switch"
                    OnClick="ButtonMultiple_Click" />        
                <div>
                    Server Trace:
                    <br />
                    <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                </div>
            </div>
        </form>
    </body>
    </html>

    Thanks for asking
  •  06-30-2011, 10:33 AM 68287 in reply to 68286

    Re: Change MultipleFilesUpload on-the-fly

    I'm assuming since you are suggesting to use server-side code, and thus a post back, that
    there isn't away to do this on the client-side via script, correct?
     
    If that's the case, I'll probably go down the road of two upload controls instead.... what a shame though!?
     
     
  •  06-30-2011, 8:38 PM 68296 in reply to 68287

    Re: Change MultipleFilesUpload on-the-fly

    Hi smcleod,
     
    Please add the javascript code below to your page and test again
     
     
    1. function CuteWebUI_AjaxUploader_OnSelect(files)  
    2.      {  
    3.         if(files.length>1)  
    4.         {  
    5.             alert("you can only select one file");  
    6.             return false;  
    7.         }  
    8.         return true;  
    9.      }  
     
    If you want to limit the file count, you can use a client tag such as input to mark the total selected files
    if the count is greater than the number you defined,
    please return false 
     
     
    Regards,
    Jeff 
  •  07-01-2011, 7:34 AM 68311 in reply to 68296

    Re: Change MultipleFilesUpload on-the-fly

    Thanks Jeff, that's a good work-around and beats adding a second upload control for just that one thing. :)
View as RSS news feed in XML