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

am working on 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

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

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

<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
Share this answer
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.


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