Ashx method of calling ASPX.cs

Source: Internet
Author: User

The problem comes from the forum, there are netizens such requirements, in the ASHX call ASPX.cs a method or function.

In a Web site, there may be more than one ASPX page.
Declare the method inside the Aspx.cs as Public,ashx want to call, and do not know which Aspx method is inside.
is a certain aspx.cs has quoted this ashx, this ashx also do not know the method of calling in the current ASPX.

In order to solve the above problem, Insus.net creates an interface (interface)

In the site, create an ASPX with the name called A.aspx. No code is written in A.aspx, but within A.aspx.cs, you need to implement the interface that you just wrote:

Now we write a handler: The name is b.ashx:

Test run to see:

The following content is added and collated in 2014-04-11 08:10:
In the development of the Web site, many times want to PageA.aspx.cs to call PageB.aspx.cs within the method, or in turn, PageB.aspx.cs want to call the method in PageA.aspx.cs.
Under normal circumstances, it is not possible to instantiate the call after. If you refer to this method, it can be solved.
As an example:

Define a say method in PageB.aspx.cs:

Then PageA.aspx.cs to call the Say method inside the PageB.aspx.cs:

Web page Execution Results:

Since the use of reflective reflection, it can also save the interface.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.