Preface
In my girlfriend's words: Hey, sorry! Busy! It's really lazy! I haven't written articles for a long time. On the one hand, I think there are not many things to write, and on the other hand, I am very busy at work. So there is no delay in everyone's time. Let's go to the theme!
BEGIN
First, we need to understand the principle that no matter how many ASCX files are installed in An ASPX page, we still need to generate code for a page, so there is no doubt, I think I have determined that this problem can be solved before solving it. Directly paste the code. First, the user control calls the parent page: // obtain the parent page
Page p = this. Parent. Page;
Type pageType = p. GetType ();
// Method name of the parent page
MethodInfo mi = pageType. GetMethod ("Loading ");
// Execute
Mi. Invoke (p, new object [] {"parameter 1", "parameter 2 "});
Call between a user control and a user control:
// Obtain the parent page
Page p = this. Parent. Page;
// Obtain the child control of the parent page
UserControl uc = p. FindControl ("tj_ReceiptList2") as UserControl;
Type pageType = uc. GetType ();
// Parent class method name
MethodInfo mi = pageType. GetMethod ("Loading ");
// Parameters
Mi. Invoke (uc, new object [] {"parameter 1", "parameter 2 "});
Supplement:
1. If you want to obtain the return value of the method, the return value of the Invoke method is the return value of the method execution. The type is object. You can just convert it!
2. I still wrote a value transfer on the title, but not in the code? Oh, can we get the value in a way that we can? In addition, there are many ways, so I won't talk about it here :)
Note:
The method for calling the parent page or other user controls must be public!
END