Click here to Skip to main content
15,894,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Whenever a textbox is empty in the
OnClientUploadStarted
method it should not allowed to add the file and it should display a message.

I had tried the following code but it is not working.
Kindly help.
Thanks in advance

What I have tried:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="usercpntrol.ascx.cs" Inherits="usercpntrol" %>
<script type="text/javascript">
      function uploadStarted(sender,args) {
            var data;
            data = document.getElementById("ucattachfile_TextBox1").innerHTML;

            if (data == "") {
                document.getElementById("Label1").innerHTML = "text value req";
                return;
            }
            else {
                 document.getElementById("Label1").innerHTML = "uploadStarted";
            }
          
        }
        function test() {

        }
        function test2() {

        }
</script>
<div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
       <ContentTemplate>
           <asp:Panel ID="Panel1" runat="server">
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
          <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1"  OnClientUploadComplete="test" OnClientUploadError="test2" 
                OnClientUploadStarted="uploadStarted" runat="server" />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
           </asp:Panel>
       </ContentTemplate>
    </asp:UpdatePanel>
 </div>
Posted
Updated 5-May-19 18:07pm
Comments
Christian Graus 5-May-19 23:51pm    
Honestly, I don't understand why people would use ASP.NET in 2019, but ASP.NET without jquery?
F-ES Sitecore 6-May-19 6:34am    
You might be better tackling this another way, which is to disable the file upload and only enable it when you have updated the text boxes to have values. Looking at the documentation it doesn't look like the asynchfileupload exposes the desired events that allow it to do what you want. You could possibly try and attach an onchange event to the file upload and use that. Also you don't need the UpdatePanel, that might complicate things too.

Another solution would be to simply use an asynch upload jquery plug-in that will almost certainly support the kind of validation you want to do.
Richard Deeming 9-May-19 13:14pm    
NB: A TextBox will be rendered as an <input> element. The input element doesn't have an innerHTML property. You need to look at the value property instead.
data = document.getElementById("ucattachfile_TextBox1").value;

1 solution

Learn to use the Chrome debugger. Debug your function. Type something into the box, and make sure it appears. You can also use alert for this.

Once you know you're getting the value, and what it is, you can fix your code.

All of this is pretty old school, you really should not be writing websites in ASP.NET in 2019
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900