skip to Main Content

i have a page with 2 textbox items and a button
textbox1 contains a word , and textbox2 is empty

now i want to put content of TextBox1.Text in TextBox2.Text with button click,

i tried:

protected void Button1_Click(object sender, EventArgs e) 
{ Page.FindControl("TextBox2").Text = TextBox1.Text; }

this code don’t work ,how to make this work?

2

Answers


  1. TextBox textbox2= (TextBox)FindControlRecursive(Page, "TextBox2");
    

    try using this, referencing this article

    Login or Signup to reply.
  2. you need to define it first then apply properties

    protected void Button1_Click(object sender, EventArgs e) 
    { 
        TextBox textBox2 = (TextBox)Page.FindControl("TextBox2");
        textBox2.Text = TextBox1.Text; 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search