0

I am using asp.net file upload

<asp:FileUpload ID="ImageUploader" runat="server"/>

how can i detect that asp:FileUpload has a file using Jquery?

I am doing this

$("#ctl00_MainContentPlaceHolder_UCUpdOrgProfile1_ImageUploader").change(function (e) {
alert("hello")
            });

But i dont know either file is selected or not.

1
  • As in the field is populated? Commented Nov 22, 2013 at 11:46

2 Answers 2

2

check -

if (document.getElementById('<%= ImageUploader.ClientID %>').files.length === 0) 
{
   // File upload do not have file
}
else {
   // File upload has file
}
Sign up to request clarification or add additional context in comments.

1 Comment

"depricated" , it does work as a charm but it adds unnecessary overhead validation, since ASP4+ there is a ClientIDMode property that can be set to static.
1

Valid answers, or since ASP 4+ just set ClientIDMode as a page property:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" ClientIDMode="Static" %>

The ClientID value is set to the value of the ID property. If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains. - reference

ie. this will force ASP to obey the ID as declared and not generate the "ctl00_" prefix or any other. This is awesome as it is applied to the whole page and all asp controls contained on it, no extra code, no hacks just one awesome property.

So apply the same logic as @Microsoft_DN solution, but use static ID's.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.