How to get the logged in user
-
protected void Page_Load(object sender, EventArgs e)
{
IterateParentsForLoginId( Parent );
}private void IterateParentsForLoginId(Control parent)
{
if (typeof( Page ).IsAssignableFrom( parent.GetType() ))
{
_loggedInId = ((Page)parent).LoggedInId;
}
else
{
if (parent.Parent != null)
IterateParentsForLoginId( parent.Parent );
else
throw new InvalidOperationException(
"To ensure proper page functioning, the containing page for this control must derive from OURNAMESPACE.Page." );
}
}<< Nearly all men can stand adversity, but if you want to test a man's character, give him power. >>
-
protected void Page_Load(object sender, EventArgs e)
{
IterateParentsForLoginId( Parent );
}private void IterateParentsForLoginId(Control parent)
{
if (typeof( Page ).IsAssignableFrom( parent.GetType() ))
{
_loggedInId = ((Page)parent).LoggedInId;
}
else
{
if (parent.Parent != null)
IterateParentsForLoginId( parent.Parent );
else
throw new InvalidOperationException(
"To ensure proper page functioning, the containing page for this control must derive from OURNAMESPACE.Page." );
}
}<< Nearly all men can stand adversity, but if you want to test a man's character, give him power. >>
the method should be called
RecursiveParentsForLoginId
-
the method should be called
RecursiveParentsForLoginId
If rewritten properly this method is tail-recursive and thus ipso facto iterative (by nature).