HOW TO CHECK IF AN ASP.NET FILE UPLOAD CONTROL HAS A FILE IN JQUERY?

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#  JQuery 
 1226  View(s)
Ratings:
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.

  1. Tanuj Kumar

    Post:134

    Points:940
    Re: How to check if an ASP.Net File Upload Control has a file in JQuery?

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!