Click here to Skip to main content
13,138,857 members (53,668 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I tried my level best to adopt a required field validator for my FileUpload. It is not working. Can anyone guide me please.
--%><asp:Panel ID="Panel117" runat="server"
        style="border-width: 1px; border-style: solid; top: 400px; left: 1185px; position: absolute; height: 161px; width: 279px; background-color:InactiveBorder; border-color:Black">
            <asp:Image ID="ImagePreview" runat="server" Height="97px" Width="99px"
            style="z-index: 1"/>
            <asp:FileUpload ID="PhotoUpload" runat="server"
              style="z-index: 1; left:100px; top: 53px; position: absolute; height: 46px; width: 218px; right: 90px;" />
           <asp:Button ID="Button7" runat="server" CausesValidation="False"
            style="z-index: 1; left: 7px; top: 123px; position: absolute"
            Text="Show" />
<%--<asp:AsyncPostBackTrigger ControlID="Button3" EventName="Click" />--%>
<asp:PostBackTrigger ControlID="Button2" />

    <asp:requiredfieldvalidator id="rfvWeeklyCommentary" runat="server" controltovalidate="PhotoUpload"
 errormessage="Select a foto."
Posted 12-May-13 5:19am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Input (File) is an HTML control, so you will need to run it as a server control and then validate it on the code-behind. If you don't want to set it a server control, you can validate it using JavaScript/jQuery in the client-side.
For instance,
var fileUpload = $("*[id$='fileUpload ']").val();
if(fileUpload == ""){
//Do your validation here
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

see this may helpful to u.

             if (!fileupload.HasFile)
                lbl.Visible = true;
                lbl.ForeColor = Color.Red;
                lbl.Text = "Please Select file";    //checking if file uploader has no file selected
                // if file is selected. 
thank u.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Required filed validator wont work
check whether it has file or not using


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100