The problem came from the Forum. Some netizens asked me to call a method or function of ASPX. cs in ASHX.
In a website, there may be more than one aspx webpage.
Declare the method in aspx. cs as public. When ashx wants to call, it does not know which method in aspx is used.
That is, a certain aspx. cs has referenced this ashx, and this ashx does not know that the call method is in the current aspx.
To solve the problem above, Insus. NET creates an interface (Interface)
In the site, create An aspx named A. aspx. No code is written in a. aspx, but in a. aspx. cs, You need to implement the interface you just wrote:
Now we write a Handler named B. ashx:
Test run:
:
When developing an asp.net website, you often want to PageA. aspx. in cs, you want to call PageB. aspx. in cs, or vice versa, PageB. aspx. in cs, you want to call PageA. aspx. methods In cs.
Generally, call is not allowed after instantiation. You can solve this problem by referring to this method.
For example:
Define a Say method in PageB. aspx. cs:
Then, PageA. aspx. cs calls the Say method in PageB. aspx. cs:
Webpage execution result:
Now that Reflection is used, you can save the interface.