Tuesday, February 3, 2009

How to Access controls on Master Pages from Content Pages in ASP .NET

We will assume that we have a Label control called "Label1" on your Master Page, you might want to change the text of that Label.
To do that write this code in your content page:
Label lbl = new Label();
lbl = (Label)Master.FindControl("Label1");
lbl.Text = "Text";
Of course, this is all assuming the label is OUTSIDE the ContentPlaceHolder

Source: https://www.nilebits.com/blog/2003/05/how-to-access-controls-on-master-pages-from-content-pages-in-asp-net/

2 comments:

  1. Very helpful

    Thanks

    ReplyDelete
  2. M.Gamal (and this is smart code )

    [c#]
    ontxtName textChanged event

    btnOK.Enabled=(txtName.Text !="")


    [eng_mohamed_gamal2@yhoo.com]

    ReplyDelete