Home > DeveloperSection > Forums > How to check if an ASP.Net File Upload Control has a file in JQuery?
Ankit Singh

Total Post:341

Points:2389
Posted on    January-19-2015 10:41 PM

 ASP.Net C#  JQuery 
Ratings:


 1 Reply(s)
 884  View(s)
Rate this:

So I'm writing a custom validator and I need to check if a file has been uploaded using the asp.net File Upload Control.

So far I have:

function validate(sender, args)

{

    if ($('#<%= hdnID.ClientID%>').val() != "False")

    {

        args.IsValid = true;

    }

    else

    {

        if ($('#<%= fup.ClientID %>').val() != '' )

        {

            alert("Run some code here");

        }

        else

        { }

    }

 }

The bit that is not right is

if ($('#<%= fup.ClientID %>').val() != '' )

I'm not sure how to determine whether the control has a file or not. Any suggestions would be awesome. Thanks.



Tanuj Kumar

Total Post:134

Points:940
Posted on    January-19-2015 11:48 PM

This might not be the JQuery-est way of doing it, but I've had success with something like this:

var uploader = $get("<%= fup.ClientID%>");

if (uploader.value != "") {

   //has files

}

I also usually check that uploader != null before checking the value. Hope that helps!


Modified On Mar-15-2016 05:42:56 AM

Don't want to miss updates? Please click the below button!

Follow MindStick