How to Make RadUpload field required

Thread is closed for posting
9 posts, 0 answers
  1. Jeff
    Jeff avatar
    38 posts
    Member since:
    Jan 2008

    Posted 12 Dec 2008 Link to this post

    We have a single video upload field as part of a larger form. All fields in the form, including the upload field, need to be required. We're having trouble figuring out how to make the radupload field required as the required field validator control won't work with radupload.

    I saw an earlier question on the same topic but the answer just referred back to the custom validator which seems to validate for file type and size but I didn't see anywhere where it would validate that there is actually a file selected.

    thanks for any help/direction you can give.

    Jeff
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 16 Dec 2008 Link to this post

    Hi Jeff,

    Please find attached a sample page which shows how to validate the upload with a custom validator.

    We will add such an example in the our documentation as well.

    I hope this helps.

    Regards,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeff
    Jeff avatar
    38 posts
    Member since:
    Jan 2008

    Posted 05 Jan 2009 Link to this post

    The sample code above worked great as a validation for a single upload file. Thanks for that.

    We now have a multiple file upload (5 fields) in which all five are required. Is there a way to adjust the code you supplied so that it will validate all 5 fields before uploading? Looking at your sample code it looks like it should do that but even when I try it directly from your sample pages it performs the upload even if only one field has a file selected.

    thanks
  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 06 Jan 2009 Link to this post

    Hello Jeff,

    Yes, this can be achieved.

    Please use the following javascript validation function:

    function validateRadUpload(source, e) 
        e.IsValid = false
         
        var upload = $find("<%= RadUpload1.ClientID %>"); 
        var inputs = upload.getFileInputs(); 
        for (var i = 0; i < inputs.length; i++) 
        { 
            //check for empty string or invalid extension 
            if (inputs[i].value == "" || !upload.isExtensionValid(inputs[i].value)) 
            { 
                return
            }             
        } 
        e.IsValid = true

    I hope this helps.

    Best wishes,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Jeff
    Jeff avatar
    38 posts
    Member since:
    Jan 2008

    Posted 06 Jan 2009 Link to this post

    That worked perfectly - thank you!
  7. vishesh kumar
    vishesh kumar avatar
    24 posts
    Member since:
    Sep 2009

    Posted 12 Jan 2010 Link to this post

    Hi,
    I have multiple upload controls on the page which should be required fields.
    Can you give a generic javascript function where i can pass the ID of the radUpload?

    otherwise i would have to write multiple functions for the raduploads
  8. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 15 Jan 2010 Link to this post

    Hi vishesh kumar,

    It is not possible because the client validation function is called by the custom validator and it does not know what controls you have on the page. So you need to manually loop through all instances of RadUpload on the page and validate against them.

    You might find this KB article useful:
    How-to create a javascript array of all particular RadControls on the page


    All the best,
    Veskoni
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Sudhanva
    Sudhanva avatar
    27 posts
    Member since:
    Apr 2009

    Posted 10 Dec 2011 Link to this post

    Whats wrong with below code? Please explain.

    <td>
                                           <telerik:RadUpload runat="server" ID="RadUpload_AccMaster" ControlObjectsVisibility="AddButton,RemoveButtons"
                                               InputSize="45" Width="500px" MaxFileInputsCount="10" InitialFileInputsCount="5"
                                               ReadOnlyFileInputs="true">
                                               <Localization Select="Browse" Add=" Add more files " />
                                           </telerik:RadUpload>
                                             
                                           <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Only mp3, m3u or mpeg files are allowed!"
                                               ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))
       +(.mp3|.MP3|.mpeg|.MPEG|.m3u|.M3U)$" ControlToValidate="RadUpload_AccMaster"></asp:RegularExpressionValidator>
                                           <br />
                                           <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="This is a required field!"
                                               ControlToValidate="RadUpload_AccMaster"></asp:RequiredFieldValidator>
                                       </td>
  10. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 14 Dec 2011 Link to this post

    Hi Sudhanva,

    The problem with your implementation is the fact that you could not directly use regular expression validator and pass the id of the RadUpload as control to be validated. Instead you should use custom validator and follow the approach suggested by my colleague Veselin.

    Kind regards,
    Dimitar Terziev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017