简体   繁体   中英

How to access page controls from master page?

I am aware that many of the content pages will create textBox controls with lets say txtCustomerName. And if this is found I need to update the value from session. In this particular case I can not move these controls to master page.

How do you access page controls from master page. And in which event of page life cycle should we attempt to do this ?

You can find in any Event you would like to, like in this example I am showing you on Button Click Event

protected void Button1_Click(object sender, EventArgs e)
{
   TextBox TextBox1 = ContentPlaceHolder1.FindControl("TextBox1") as TextBox;
   if (TextBox1 != null)
   {
       Label1.Text = TextBox1.Text;
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM