How to Add required validate atleast one uploader is required using javascript or anything else
Loading
How to Add required validate atleast one uploader is required using javascript or anything else
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mohammad HussainRank #513 · 4.8K reputationPosted Sep 21, 2023, 7:28 AM EDT
Add your
asp:FileUploadcontrols to your ASP.NET page:Add a validation function and a hidden field to store the validation result in your ASP.NET page:
function validateFileUpload() { var fileUpload1 = document.getElementById(''); var fileUpload2 = document.getElementById(''); var fileUpload3 = document.getElementById(''); // Check if at least one FileUpload control has a file selected if (fileUpload1.value || fileUpload2.value || fileUpload3.value) { document.getElementById('').value = "true"; } else { document.getElementById('').value = "false"; alert("At least one file upload is required."); return false; // Prevent form submission } return true; // Allow form submission }Add a button on your ASP.NET page and attach the
validateFileUploadfunction to itsonclickevent:protected void btnSubmit_Click(object sender, EventArgs e) { if (hdnUploadRequired.Value == "true") { // At least one file upload was selected; proceed with your logic here } else { // No file uploads were selected; show an error message or take appropriate action } }Saravanan GanesanRank #153 · 15.1K reputationPosted Sep 24, 2023, 12:54 PM EDT
To validate that at least one file uploader is required in a web form using JavaScript, you can use the following approach:
Saravanan GanesanRank #153 · 15.1K reputationPosted Sep 24, 2023, 1:27 PM EDT
To validate that at least one file uploader is required in a web form using JavaScript, check if any of the file input elements have a selected file. If none do, show an error message. You can use the
input[type="file"]:validselector in conjunction with the:invalidpseudo-class to implement this validation.