Hi,
Based on my understanding, you want to know how to call the method that is declared on the page from UserControl. If I have misunderstood you, please feel free to let me know.
We can call the method that is declared on the page from UserControl in the asp.net 2.0. For example, we can create an abstract base class for the Page in the App_Code folder. The following is the abstract base class which will be inherited by the Page:
/// <summary>
/// Summary description for AbstractBaseClass
/// </summary>
public abstract class AbstractBaseClass : System.Web.UI.Page
{
public AbstractBaseClass()
{
//
// TODO: Add constructor logic here
//
}
public abstract int DoSomething();
}
In the Page, we need to inherit this base class and override the abstract method declared in the base class:
public partial class UserControl_Default : AbstractBaseClass
{
protected void Page_Load(object sender, EventArgs e)
{
}
public override int DoSomething()
{
return 1 + 1;
}
}
In the UserControl, We just need to call the method which exists in the base class:
public partial class UserControl_WebUserControlA : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
AbstractBaseClass page = (AbstractBaseClass)Page;
int iResult = page.DoSomething();
}
}
I hope this helps.