HOW TO ACCESS PAGE CONTROLS FROM MASTER PAGE?

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
 803  View(s)
Ratings:
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 ?

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: How to access page controls from master page?

    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;

       }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!