This is a migrated thread and some comments may be shown as answers.

How to Make RadUpload field required

8 Answers 304 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 12 Dec 2008, 10:31 PM
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

8 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 16 Dec 2008, 09:37 AM
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.
0
Jeff
Top achievements
Rank 1
answered on 05 Jan 2009, 06:56 PM
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
0
Veselin Vasilev
Telerik team
answered on 06 Jan 2009, 09:30 AM
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.
0
Jeff
Top achievements
Rank 1
answered on 06 Jan 2009, 04:47 PM
That worked perfectly - thank you!
0
vishesh kumar
Top achievements
Rank 1
answered on 12 Jan 2010, 07:59 AM
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
0
Veselin Vasilev
Telerik team
answered on 15 Jan 2010, 03:00 PM
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.
0
Sudhanva
Top achievements
Rank 1
answered on 10 Dec 2011, 08:05 PM
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>
0
Dimitar Terziev
Telerik team
answered on 14 Dec 2011, 03:09 PM
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
Tags
Upload (Obsolete)
Asked by
Jeff
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Jeff
Top achievements
Rank 1
vishesh kumar
Top achievements
Rank 1
Sudhanva
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or