Home > ASP.Net, Javascript > Disable Button Click untill Check a CheckBox

Disable Button Click untill Check a CheckBox


Hi

try this example:

Step 1 : Place a CheckBox an button on page

<asp:CheckBox ID="CheckBox1" runat="server" Text="Agree" />
<asp:Button ID="Button1" runat="server" Text="Button"  Enabled="false" />

step 2: add following javascript to the page:
 

<script type="text/javascript">
    function SetStatus()
    {
      
        if(document.getElementById('<%=CheckBox1.ClientID%>').checked)
        {
            document.getElementById('<%=Button1.ClientID%>').disabled = false;
        }
        else
        {
            document.getElementById('<%=Button1.ClientID%>').disabled = true;
        }
        return false;
    }
    </script>

Step 3: Add Attribute the CheckBox

CheckBox1.Attributes.Add("onchange", "SetStatus();");

Good Luck

Advertisements
Categories: ASP.Net, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: