0

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
  • FindControl does not recursively search containers so maybe it is not a direct child of Page. Why not just TextBox2.Text = TextBox1.Text; ? Commented Feb 1, 2023 at 2:03
  • real use case is more complicated and will take long lines to describe , is there any other valid method ? , in windows forms i used to do: this.Controls.Find("textBox2", true)[0].Text = textBox1.Text; , but this don't work in asp.net Commented Feb 1, 2023 at 2:06

2 Answers 2

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

try using this, referencing this article

Sign up to request clarification or add additional context in comments.

Comments

0

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; 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.