Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<script type="text/javascript">

            function disableApprove(form) {
                if (form.chkApproved.checked) {
                    form.imgs.disabled = false;
                }else{
                    form.imgs.disabled = true;
                }
            }
  </script>


C#
<asp:ImageButton ID="imgs" runat="server" ImageUrl="images/-trash.png" OnClick="imgs_Click" Width="40px" Height="40px"   />

  <table><tbody><tr><td><asp:CheckBox ID="item_check" runat="server" OnCheckedChanged="item_check_CheckedChanged" Checked="true" /></td></tr></tbody></table>
Posted
Updated 2-Dec-14 20:42pm
v2
Comments
Deepu S Nair 3-Dec-14 2:19am    
hey,What is your question about?
Member 10918596 3-Dec-14 2:29am    
my code not working

Jquery code:
XML
<script type="text/javascript">
        $(document).ready(function () {
            $("#item_check").click(function () {
                if ($(this).is(":checked"))
                    $("#imgs").attr("disabled", false);
                else
                    $("#imgs").attr("disabled", true);
            });
        });
</script>

Markup:
XML
<asp:ImageButton ID="imgs" runat="server" ImageUrl="images/-trash.png"  Width="40px" Height="40px" clientidmode="static" />

<asp:CheckBox ID="item_check" runat="server"  clientidmode="static" />

Regards...
 
Share this answer
 
Comments
Praveen Kumar Upadhyay 3-Dec-14 2:43am    
Great! I have rated you 2
try this

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">

        function disableApprove(chk) {
            var imgs = document.getElementById('imgs');
            if (chk.checked)
                imgs.disabled = false;
            else
                imgs.disabled = true;

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ImageButton ID="imgs" runat="server" ImageUrl="images/-trash.png" OnClick="imgs_Click"
            Width="40px" Height="40px" />
        <table>
            <tbody>
                <tr>
                    <td>
                        <asp:CheckBox ID="item_check" runat="server" onclick="  disableApprove(this); " />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
Member 10918596 3-Dec-14 4:18am    
first, when i load page image visible...
Karthik_Mahalingam 3-Dec-14 5:23am    
ok, check inside the code behind, u would have made it as visible=false.
Set AutoPostBack="True" with your CheckBox control.

XML
<asp:ImageButton ID="imgs" runat="server" ImageUrl="images/-trash.png" OnClick="imgs_Click" Width="40px" Height="40px" />

<asp:CheckBox ID="item_check" runat="server" OnCheckedChanged="item_check_CheckedChanged" AutoPostBack="True" />



C#
protected void item_check_CheckedChanged(object sender, EventArgs e)
       {
           if (item_check.Checked)
               imgs.Enabled = true;
           else
               imgs.Enabled = false;
       }


Do the same check on Page Load

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (item_check.Checked)
                    imgs.Enabled = true;
                else
                    imgs.Enabled = false;
            }
        }
 
Share this answer
 
v4
Comments
Thanks7872 3-Dec-14 2:27am    
Why?
Member 10918596 3-Dec-14 2:29am    
my code is not working properly
Member 10918596 3-Dec-14 2:29am    
give example
Praveen Kumar Upadhyay 3-Dec-14 2:32am    
Javascript which you have posted has no link with your question. What you can do is, you can handle it in code behind. So to work checkbox Checked event to work as expected we need to allow AutoPostBack=true
Thanks7872 3-Dec-14 2:34am    
No. Why code behind when you can easily handle it on client side? See the solution i have posted.

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