在asp.net中的ajax异步文件上传控件中获取添加验证时出错。 [英] Error getting in the adding validation in ajax async file upload control in asp.net.

查看:71
本文介绍了在asp.net中的ajax异步文件上传控件中获取添加验证时出错。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当

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>

推荐答案

了解如何使用Chrome调试器。调试你的功能。在框中键入内容,并确保它出现。你也可以使用提醒。



一旦你知道你获得了价值,它是什么,你可以修复你的代码。



所有这些都是相当古老的学校,你真的不应该在2019年在ASP.NET上写网站
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


这篇关于在asp.net中的ajax异步文件上传控件中获取添加验证时出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆