Instead of trying to find or keep track of controls (which may change in future versions of your code) and modifying them with code at runtime, I would go with a more data-centric method - WPF/Silverlight are made for this.
Generate a business application sample from the visual studio project templates...check out the LoginStatus.xaml/LoginStatus.xaml.cs files to see another way of doing this with bindings and visual states.
Basically, there's a singleton/static object that represents the logged-in/logged-out state. This class has events for loggedin and loggedout. Any element (like a usercontrol) you have that needs to know when the state changes can subscribe to these events and in the event handlers set its state appropriately (like changing a "log in" button to "log out"). This puts the code right in the usercontrol's class instead of having to track or find usercontrols from other pages/controls.
For example, if you wrapped your authentication code in a singleton class like this
public class AuthenticationService : INotifyPropertyChanged
{
#region INotifyPropertyChanged Implementation
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
private static volatile AuthenticationService instance;
private static object syncRoot = new Object();
private AuthenticationService()
{
}
public static AuthenticationService Current
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new AuthenticationService();
}
}
return instance;
}
}
public event EventHandler<EventArgs> LoggedIn;
public event EventHandler<EventArgs> LoggedOut;
public void LogIn()
{
IsLoggedIn = true;
EventHandler<EventArgs> evnt = LoggedIn;
if (evnt != null)
{
evnt(this, new EventArgs());
}
}
public void LogOut()
{
IsLoggedIn = false;
EventHandler<EventArgs> evnt = LoggedOut;
if (evnt != null)
{
evnt(this, new EventArgs());
}
}
bool _isLoggedIn = false;
public bool IsLoggedIn
{
get { return _isLoggedIn; }
set
{
if (_isLoggedIn != value)
{
_isLoggedIn = value;
OnPropertyChanged("IsLoggedIn");
}
}
}
}
...then a usercontrol that needs to update itself based on the loggedin/loggedout status can simply do something like this
public MyUserControl()
{
InitializeComponent();
AuthenticationService authentication = AuthenticationService.Current;
authentication.LoggedIn += new EventHandler<EventArgs>(authentication_LoggedIn);
authentication.LoggedOut += new EventHandler<EventArgs>(authentication_LoggedOut);
}
void authentication_LoggedIn(object sender, EventArgs e)
{
}
void authentication_LoggedOut(object sender, EventArgs e)
{
}
No need for another page to know about MyUserControl :)