-2

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 ?

user14567
  • 3
  • 2

1 Answers1

0

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();
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • I tried to do it but it says it could not be found, I trying calling the namespace and including in the c# file , but it throws an error. – user14567 Jul 17 '17 at 20:20