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

Total Post:341

Points:2389
C#  JQuery 
 1578  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. 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 Apr-08-2018 11:35:01 PM

Answer

NEWSLETTER

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