Forums

How to stop ASPxUpload uploading files on form submit

Last post 5/27/2009 7:05 AM by Dan Maharry. 4 replies.
Sort Posts: Previous Next
  • Dan Maharry

    How to stop ASPxUpload uploading files on form submit

    5/26/2009 5:30 AM
    • Not Ranked
    • Joined on 5/26/2009
    • Posts 13

    Hello,

    I have an ASPxUpload control in a simple form allowing users to upload files to be associated with online articles. However, if the form's submit button is clicked, any files currently chosen in the upload form are automatically uploaded. How do I stop the UploadControl uploading files to the server when a form submit is clicked. I tried uploader.Cancel(); in the button's onClientClick event but that didn't work.

    Thanks in advance. 

    Filed under:
  • Andrew R (Developer Express)

    Re: How to stop ASPxUpload uploading files on form submit

    5/27/2009 3:57 AM

    Hi!

    The ASPxUploadControl uses the standard input element with the type="file" to upload files.
    The input element always uploads a selected file when form submitting is performed.
    When submitting a form, all form data is sent to the server, and file uploading is performed.
    It's impossible to cancel file uploading only. It's possible to cancel form submitting only.
    Here is the code, implementing this behavior:

    <script type="text/javascript">

        function IsUploadAllow() {

            var cancelUpload = true;

            // some conditions

            return !cancelUpload;

        }

    </script>

    <form id="form1" runat="server" onsubmit="return IsUploadAllow();">       

        <input id="Submit1" type="submit" value="submit" />

    </form>

    The client-side ASPxClientUploadControl.Cancel method allows you to cancel file uploading via callback only.
    You can learn more about this method from the following help topic:

    http://www.devexpress.com/Help/?document=ASPxperience/DevExpressWebASPxUploadControlScriptsASPxClientUploadControl_Canceltopic.htm

  • Dan Maharry

    Re: How to stop ASPxUpload uploading files on form submit

    5/27/2009 6:23 AM
    • Not Ranked
    • Joined on 5/26/2009
    • Posts 13

    Hi Andrew,

    Thanks for getting back to me. If that is the case, how do I loop through all the file input elements within an Upload control? GetText() returns only the contents of the first input element and GetControlCollection() is not recognised as a function of ASPxClientUploadControl. What I need to do is check that all file input elements in the Upload control are blank and if that is the case, then allow the form submission to proceed, otherwise cancel the form submit.

    Thanks, dan

  • Andrew R (Developer Express)

    Re: How to stop ASPxUpload uploading files on form submit

    5/27/2009 6:47 AM

    Hi!

    Use the client-side ASPxClientUploadControl.GetText method with an integer parameter, for example:

    function IsAllowUpload() {

        for (var i = 0; i < upload.GetFileInputCount(); i++) {

            var fileName = upload.GetText(i);

            if (fileName != "")

                return false;

        }

        return true;

    }

  • Dan Maharry

    Re: How to stop ASPxUpload uploading files on form submit

    5/27/2009 7:05 AM
    • Not Ranked
    • Joined on 5/26/2009
    • Posts 13

    Hi Andrew,

    That works a treat. Thanks for pointing out that GetText can also take an integer parameter. I had missed that.

    Dan

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.