This is a migrated thread and some comments may be shown as answers.

Disable Button on CheckBox unchecked

3 Answers 162 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ebenezer
Top achievements
Rank 1
Ebenezer asked on 16 Oct 2013, 01:52 AM
I am using the code below to force customers to select item from a Grid CheckBox
function GetCheckedItemCountbtnClick() {
            var checkedcount = 0;
            var grid = $find("<%=gvSummary.ClientID %>");           
            for (var i = 0; i < grid.get_masterTableView().get_dataItems().length; i++) {
                var objchkbox = grid.get_masterTableView().get_dataItems()[i].findElement("CheckBoxStatus");
                 if (objchkbox.checked) {
                    checkedcount++;
                }
                 
                //}
                if (checkedcount > 8) {
                     objchkbox.checked = false;
                  
                    alert("Please select only 8 item");
                    return false;                  
 
                }
            }
            if (checkedcount == 0) {
                  
                alert("Please Check at least one CheckBox");
                 
                return false;
 
            }
 
         
        }


I have a Button I want to disable when the 'checkedcount ==0' unless an item is checked
<asp:Button ID="btnPrint" runat="server" Font-Size="X-Small" OnClick="btnPrint_Click"
                            Text="Print" ToolTip="Create a  report..." />

Nothing seems to work for me. Any idea will be appreciated.





3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 16 Oct 2013, 06:17 AM
Hi Ebenezer,

I guess you are trying to disable the Button 'btnPrint' on another Button Click. Please have a look into the following code snippet that I tried.

ASPX:
<telerik:RadButton ID="RadButton1" runat="server" Text="CheckedItems" OnClientClicked="GetCheckedItemCountbtnClick"
    AutoPostBack="false">
</telerik:RadButton>
<br />
<asp:Button ID="btnPrint" runat="server" Font-Size="X-Small" Text="Print" ToolTip="Create a  report..." />

JavaScript:
<script type="text/javascript">
    function GetCheckedItemCountbtnClick(sender, args) {
        var checkedcount = 0;
        var grid = $find("<%=gvSummary.ClientID %>");
        for (var i = 0; i < grid.get_masterTableView().get_dataItems().length; i++) {
            var objchkbox = grid.get_masterTableView().get_dataItems()[i].findElement("CheckBoxStatus");
            if (objchkbox.checked) {
                checkedcount++;
            }
            if (checkedcount > 8) {
                objchkbox.checked = false;
                alert("Please select only 8 item");
                return false;
            }
        }
        if (checkedcount == 0) {
            alert("Please Check at least one CheckBox");
            var button = document.getElementById("btnPrint");//accessing the asp button
            button.disabled = true;//disabling the button
            return false;
        }
    }
</script>

Thanks,
Shinu.

0
Ebenezer
Top achievements
Rank 1
answered on 16 Oct 2013, 01:08 PM
Hi Shinu
Thanks for your response but I am getting an error
Error: Unable to set value of the property 'disabled': object is null or undefined
0
Ebenezer
Top achievements
Rank 1
answered on 16 Oct 2013, 02:58 PM
Solved. I had to change
if (checkedcount == 0) {
                alert("Please Check at least one CheckBox");
                var button = document.getElementById("<%=btnPrint.ClientID %>"); //accessing the asp button       
                button.disabled = true; //disabling the button
                return false;
            }
Tags
General Discussions
Asked by
Ebenezer
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Ebenezer
Top achievements
Rank 1
Share this question
or