Reputation: 3
I am passing an instance of UserControl as this to the Constructor of the Class which inherits the Page Class and Itemplate Interface , I am saving the instance of type userControl , Now How can I access the methods of the user Control. For Ex, MyUserControl file name is uc_test and The Class datagridtemplate:Page, Itemplate
My UserControl has partial class name uc_test and have method
public int addtwonumbers()
{
return 10+20;
}
datadatagridtemplate x = new datagridtemplate(this); //new instance
In the datagridtemplate.cs file :
public datagridtemplate(UserControl uc){}
in In one of method of datagridtemplate class I want to do following
int sum = uc.addtwonumbers();
Now I wanted to access all the methods and properties defined in the uc_test , how can I achieve this ?
Upvotes: -2
Views: 61
Reputation: 39132
My UserControl has partial class name uc_test
As suggested by Jack Miller, cast your generic UserControl reference to the correct type that you created:
uc_test ucTst = (uc_test)uc;
int sum = ucTst.addtwonumbers();
Upvotes: 0