Home > DeveloperSection > Forums > How to access page controls from master page?
Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Posted on    August-28-2014 1:55 AM

 ASP.Net
Ratings:


 1 Reply(s)
 597  View(s)
Rate this:

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 ?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-28-2014 3:08 AM

Hi Samuel, 

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;

   }

}


Don't want to miss updates? Please click the below button!

Follow MindStick