FindControl from C# Class

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I'm not sure if this is the correct approach or not. I'm trying to
create a class for Functions that are used on a regular basis. On
function will be to set the Text value that sits on the MasterPage.
How do I do this? I don't see Page or FindControl anywhere. Thanks
 
Dave said:
I'm not sure if this is the correct approach or not. I'm trying to
create a class for Functions that are used on a regular basis. On
function will be to set the Text value that sits on the MasterPage.
How do I do this? I don't see Page or FindControl anywhere. Thanks

In your class file, import the namespace "System.Web". Then do the
following:

Page myPage = (Page)HttpContext.Current.Handler;

This gives you a reference to the page that called the method in your class.
From there, you can use the .Master property to get to the Master page, and
either cast it to the type of your masterpage and directly access the
control, or use FindControl on the Masterpage.
 
Back
Top