Use html + ashx to implement the aspx Function

Source: Internet
Author: User

Recently, I am going to learn ASP. NET. I have read some video tutorials on the Internet at the early stage, and I am going to organize my learning items for reference later.

This article uses html and ashx to implement aspx, achieving the simplest dynamic web page effect. The development environment is VS2012. The Demo structure is as follows:

  

The aspx file is a Microsoft dynamic web page file running on the server. After being parsed and executed through IIS, you can get a dynamic page, which includes the aspx file and aspx. cs file, as shown in. One is used to control the foreground, and the other is to control the background. The classes in the aspx. cs file Inherit System. Web. UI. Page, while the Page class implements the IHttpHandler interface. We know that classes in the ashx. cs file also implement IHttpHandler. Aspx only goes through some more complex processing. It achieves the same effect as implementing dynamic pages with ashx and html. The following shows a TextBox and a Button, which respectively display the interaction between the client and the server in two ways.

Specific implementation process:

1. Use aspx:

The index. aspx code is as follows:

Index. aspx

The index. aspx. cs code is as follows:

Page_Load (button#click (str = Response. Write (+}Index. aspx. cs

2. html + ashx:

The code for index.html is as follows:

Index.html

The server. ashx code is as follows:

Context. Response. ContentType = str = context. Request [context. Response. Write (+ fullPath = context. Server. MapPath (content =}Server. ashx

Enter "snail Il" in the TextBox and click "Send request". The results are as follows:

It can be seen that the effects of html + ashx and aspx are basically the same. The only difference is that after the aspx implementation example sends a request, the TextBox value can still be seen. The value in the text box after the request is sent in html + ashx is empty because the initial value of the re-drawn text box in the ProcessRequest method in ashx is empty. In fact, the essence of aspx is implemented through html + ashx, but Microsoft encapsulates it.

 

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.