Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var chk = new CheckBox();
chk.CheckedChanged += chkBox_CheckedChanged;

private void chkBox_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is CheckBox)
            {
                CheckBox checkbox = sender as CheckBox;
                if (checkbox.Checked)
                {
                    checkbox.Text = "Checked";
                }
                else
                {
                    checkbox.Text = "UnChecked";
                }
            }
        }
Posted
Updated 9-Apr-13 1:37am
v3
Comments
Shine Ashraf 9-Apr-13 4:07am    
where you added (event ?) this code ?
Kurac1 9-Apr-13 4:13am    
On button upload i display a hyperlink and a checkbox in a repater when checkbox is selcted on item i want want to display a delete button
Shine Ashraf 9-Apr-13 4:41am    
on above code, you have initialized a check box, and it's default checked state is false.
How you handling the check box's checked change event ?
Kurac1 9-Apr-13 4:50am    
se above code
Shine Ashraf 9-Apr-13 4:53am    
but you are not changing the button visibility.

1 solution

First attach the javascript function to your checkbox
chk.Attributes.Add("onclick", "enableDeleteButton();");

This will call function enableDeleteButton everytime you chick on checkbox. Also below is the function you can use:

C#
function enableDeleteButton() {
            debugger;


            var repeater = document.getElementById('repeater');  // This is div to limit //the controls to repeater checkbox.
            var delbutton = document.getElementById('<%=btnDelete.ClientID%>');
// make button visible false first 
            delbutton.style.display = 'none';
            var inputs = repeater.getElementsByTagName('input');
            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].type == "checkbox" && inputs[i].checked == true)
                    delbutton.style.display = '';
            }
        }


And in page load make delete button visible false by adding below code:

btnDelete.Style.Add("display", "none");

[Do not use btn.Visible = False as it will not find by javascript]

Let me know if need any help.
 
Share this answer
 
Comments
PrashantSonewane 9-Apr-13 7:20am    
Mark as answered if it works for you...

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