Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

am working on Asp.net c# Sqlsever 2005.

I have a web page which consists of Checkbox and Textboxes.

When the first time page loads these textboxes are disabled. AND when user checks the checkbox the cursor must be placed in TEXTBOX.

Please help me. and give me one example on this


Thanks for ever
Posted

You can use the focus() method in JavaScript.
Here is a sample code.

XML
<script type="text/javascript">
   function setFocus()
    {
        var checkbox = document.getElementById('<%=checkBox1.ClientID %>');
        var Textbox =  document.getElementById('<%= txtTest.ClientID%>');
        if(checkbox.checked)
        {
          Textbox.disabled =false;
          Textbox.focus();
        }
        else
        {
            Textbox.disabled =true;
        }
    }
    </script>


XML
<asp:CheckBox ID="checkBox1" runat="server" OnCheckedChanged="checkBox1_CheckedChanged"  />
  <asp:TextBox ID="txtTest" runat="server" Enabled="false"></asp:TextBox>



In your code behind file include this line under Page_Load()
checkBox1.Attributes.Add("onClick", "setFocus()");
 
Share this answer
 
v2
 
Share this answer
 
Comments
Ubaid ur Rahman IT 9-Sep-12 3:08am    
Boss Boss................

Enable Textboxes when checkbox checked.
Ubaid ur Rahman IT 9-Sep-12 3:10am    
Textboxes must be same as it is....when checkbox checked user can enter into textbox.

Please help.

Thanks.

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