Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 30-Jun-10 1:27am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
Ankur\m/ at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In the CheckBox Click event:
textBox2.Text = textBox1.Text;
  Permalink  
Comments
Ankur\m/ at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If you want to do in client side then
 
1. Add onclick event handler in checkbox (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
<asp:CheckBox ID="CheckBox1" runat="server"
        oncheckedchanged="CheckBox1_CheckedChanged" />
 
And in aspx.cs page
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        TextBox2.Text = TextBox1.Text;
    }
  Permalink  
v2
Comments
Laxman Auti at 30-Jun-10 14:56pm
   
If you could give the example of java script too, that would help author a lot.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

just an addition to Answer1, you need to set autopostback=TRUE for the checkbox otherwise the checkChanged event for checkbox will not fire.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 DamithSL 165
4 Tomas Takac 144
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 4 Jul 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100