简体   繁体   English

JavaScript无法在ASP.NET中正常工作

[英]JavaScript Not Working properly in ASP.NET

I am pretty new to JavaScript and got stuck at one point: I am using asp control fileupload to upload some files and store them to database, i am using asp repeater control to show all the docs in database in front end and have associated a html checkbox to every doc: The problem is when i check or uncheck the checkbox, the delete button enables/disables accordingly, but when i click the "Select All" button where i am calling both functions - to check all checkboxes and to enable button, somehow the delete button is not getting enabled..Please help. 我对JavaScript相当陌生,只停留在一点:我正在使用asp控件fileupload上传一些文件并将它们存储到数据库中,我正在使用asp中继器控件在前端显示数据库中的所有文档并关联了html每个文档的复选框:问题是当我选中或取消选中复选框时,删除按钮会相应地启用/禁用,但是当我单击要同时调用这两个功能的“全选”按钮时,请选中所有复选框并启用按钮,不知何故删除按钮没有启用。.请帮助。

Here is JavaScript Code to enable delete button:- 这是启用删除按钮的JavaScript代码:-

function EnableButton() {
            var rpt = document.getElementById('<%= rptWordDoc.ClientID  %>');
            var chkbx = document.getElementsByTagName('input');
            var x = document.getElementById("btnDelWordDoc");
            for (i = 0; i <= chkbx.length; i++) {
                var id = "rptWordDoc_chkWordDoc_" + i
                var y = document.getElementById(id);
                if (y == null) {
                    break;
                }
                if (y.checked == true) {
                    x.disabled = false;
                    break;
                }
                else {
                    x.disabled = true;
                }
            }

        }

This is how i am calling the function:- 这就是我调用该函数的方式:-

<asp:Button ID="btnSelectAll" runat="server" Text="Select All" OnClientClick="fnSelectAll(); JavaScript:EnableButton();" />

Through Checkbox:- 通过复选框:

<input type="checkbox" id="chkWordDoc" runat="server" onclick="JavaScript:EnableButton();" />

You called two functions fnSelectAll(); 您调用了两个函数fnSelectAll(); and JavaScript:EnableButton(); JavaScript:EnableButton(); may be second is not executed after executing the first one. 可能是第二个在执行第一个之后未执行。

Finally found the cause: Actually i was using asp: button control for Select All & Clear All features and thus it was posting back to the server and setting back the value of delete button enabled attribute to false. 终于找到了原因:实际上我在使用“ asp:”按钮来“全选”和“清除所有”功能,因此它回发到服务器并将“ delete button enabled”属性的值重新设置为false。

I added a html control instead of asp button for Select All & clear all buttons and didn't added runat=server attribute since no server side event was required. 我为全选和清除所有按钮添加了html控件而不是asp按钮,并且没有添加runat = server属性,因为不需要服务器端事件。

Thanks for your suggestions.. Cheers..:) 感谢您的建议。。。。。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM