I have several UserControls that I want each of them to have some basic functions. Below is my implementation:
public interface IMyTabInterface
{
void LoadData();
}
public partial class MyFirstTab : System.Web.UI.UserControl, IMyTabInterface
{
public void LoadData()
{
...
}
}
Then, in another page code, I try:
protected void LoadFirstTab()
{
Control uControl1 = Page.LoadControl("/Controls/MyFirstTab.ascx");
Control uControl2 = Page.LoadControl("/Controls/MySecondTab.ascx");
var myFirstTab = (IMyTabInterface)uControl1;
var mySecondTab = (IMyTabInterface)uControl2;
myFirstTab.LoadData();
mySecondTab.LoadData();
Panel1.Controls.Add(myFirstTab);
Panel1.Controls.Add(mySecondTab);
}
I know that a lot of this is still wrong, but I get an error in the LoadControl () line:
"MyFirstTab" is not allowed here because it does not extend the "System.Web.UI.UserControl" class
although the class explicitly extends the UserControl class. What's going on here? Is there a better way to do this?
rusty source
share