0

I've a user control registered in an aspx page On click event of a button in the aspx page, how do i call a method which is there in the user control? I need to execute the method in user control on click event of button in aspx page.

Thanks....

1
  • You have a reference to your UserControl in your Button's click-event handler? So where is the problem to call MyUserControl.Foo() there? This function must be public. Commented Jul 13, 2011 at 7:04

1 Answer 1

2
// Below might help

UserControl B = new UserControl();
Object[] parameters = new Object[2];
parameters[0] = 45;
parameters[1] = "test"; 
B = (UserControl)Page.FindControl("[UserControlId]");
B.GetType().GetMethod("[MethodName]").Invoke(B, parameters);
Sign up to request clarification or add additional context in comments.

5 Comments

Object reference not set to an instance of an object. I m getting this error.
B.GetType().GetMethod("[copyInfo]").Invoke(B, null); In this line I m getting error
B.GetType().GetMethod("copyInfo").Invoke(B, null); remove []
How to pass parameter in the method copyinfo B.GetType().GetMethod("copyInfo").Invoke(B, null); there are two parameters to be passed
Its working now I have commented the second line in the above code B = (UserControl)Page.FindControl("[UserControlId]"); (this one) Now Plz let me know how to pass parameters in the method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.