Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I have Two TextBoxes.when I fill one TextBox Then On Clicking Checkbox,the data of TextBox will be filled into second TextBox.How It can be done.


Thanks With Regards,
Amit Mehan
Posted

Thats easy.

If you have two text boxes (textBox1 and textBox2) and a CheckBox (checkBox1) you just need to add the following line to the checkBox1.CheckedChanged EventHandler

textBox2.Text = textBox1.Text
 
Share this answer
 
Comments
Ankur\m/ 30-Jun-10 7:03am    
I would advice OP to use JavaScript to do the same. The method you have told does a unnecessary post-back.
In the CheckBox Click event:
textBox2.Text = textBox1.Text;
 
Share this answer
 
Comments
Ankur\m/ 30-Jun-10 7:04am    
I would advice OP to use JavaScript to do the same. The method you have told does a unnecessary post-back.
If you want to do in client side then

1. Add onclick event handler in checkbox (javascript)
JavaScript
function clicked(objCheckBox)
        {
            document.getElementById("<% =TextBox2.ClientID %>").value = document.getElementById("<% =TextBox1.ClientID %>").value;
        }


2. Add onclick event handler to checkbox
CheckBox1.Attributes.Add("onclick", "clicked(this)");


If you want to do in server side then simply add CheckChanged event
VB
<asp:CheckBox ID="CheckBox1" runat="server"
        oncheckedchanged="CheckBox1_CheckedChanged" />


And in aspx.cs page
C#
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        TextBox2.Text = TextBox1.Text;
    }
 
Share this answer
 
v2
Comments
Laxman Auti 30-Jun-10 14:56pm    
If you could give the example of java script too, that would help author a lot.
just an addition to Answer1, you need to set autopostback=TRUE for the checkbox otherwise the checkChanged event for checkbox will not fire.
 
Share this answer
 

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