1

I have button and file upload control in the page, i want to enable or disable button based on value of file upload control. if the file upload does not have selected file then button still disable.

The code is working fine however if you choose the file then button able (correct behaviour) then you click file upload control but this time you want to click cancel but the the button is not disable.

function enableButton() {
        var a = document.getElementById("<%=file_upload.ClientID%>")
        if (a == 0) {
            document.getElementById("<%=btnAdd.ClientID%>").disabled = true;
        }
        else {
            document.getElementById("<%=btnAdd.ClientID%>").disabled = false;
        }

   }


<asp:FileUpload ID="file_upload" runat="server" AllowMultiple="true" maxLength="10" accept="text/plain" Enabled="false" CssClass="cssFileUpload" onchange="enableButton()"/>

  <asp:Button ID="btnAdd" runat="server" Text="Add Files" onclick="btnAdd_Click" Enabled="false" />

2 Answers 2

1

document.getElementById will return null if not find any element. Use

if( a == null) {}
Sign up to request clarification or add additional context in comments.

Comments

1

I seems like the problem is that you are checking for the control it self hence a == 0. If you checked for a property such as value in addition.

if(a == null || a.value == "")

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.