Calling a base page method from a user control in asp.net

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:\[code\]public partial class MainPage : MyBasePage{ protected void Page_Load(object sender, EventArgs e) { var loginTime = GetLoginTime(); // This works fine }}\[/code\]And the base page:\[code\]public partial class MyBasePage: Page{}protected DateTime GetLoginTime(){ // Do stuff return loginTime;}\[/code\]Now I have a user control on that page that needs to call my method...Like this:\[code\]public partial class TimeClock : UserControl{ protected void Page_Load(object sender, EventArgs e) { var loginTime = GetLoginTime(); // This does not work! }}\[/code\]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:\[code\]var page = Parent as MyBasePage;page.GetLoginTime(); // This works IF I make GetLoginTime() a public method\[/code\]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!
 
Back
Top