title: Calling a base page method from a user control in asp.net
body: <p>I have been trying to find a good answer to this question, but can't seem to find one. I have an ASP.NET page that derives from a base page, like this:</p>
  
  <pre><code>public partial class MainPage : MyBasePage
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          var loginTime = GetLoginTime(); // This works fine
      }
  }
  </code></pre>
  
  <p>And the base page:</p>
  
  <pre><code>public partial class MyBasePage: Page
  {
  }
  
  protected DateTime GetLoginTime()
  {
      // Do stuff
      return loginTime;
  }
  </code></pre>
  
  <p>Now I have a user control on that page that needs to call my method...Like this:</p>
  
  <pre><code>public partial class TimeClock : UserControl
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          var loginTime = GetLoginTime(); // This does not work!
      }
  }
  </code></pre>
  
  <p>As you can see, I cannot call my base method, for obvious reasons. My question is, how can I call this method from my user control? One work around I've found is like this:</p>
  
  <pre><code>var page = Parent as MyBasePage;
  page.GetLoginTime(); // This works IF I make GetLoginTime() a public method
  </code></pre>
  
  <p>This works, if I make my function public instead of protected. Doing this doesn't seem like a very OOP way to tackle this solution, so if someone can offer me a better solution, I'd appreciate it!</p>