Use Ajax.NET to implement no refresh page in static pages

Source: Internet
Author: User
Tags config

I. INTRODUCTION

We know that the ASP.net application fact is running on the server, the user's request to be sent to the remote server, the server executes the local program after the reload page to send the client. So there is a constant refresh of the problem, the page constantly flashing. The user is tired, the operation efficiency also greatly reduces, the server load increases. In fact, a client's request retrieves a response to user input at some point only by submitting a new request to the WEB server. In this case, developers can use JavaScript to load all the responses on the client, providing a better user experience. Unfortunately, in many cases, it's better not to return or load all the responses to JavaScript, just return the desired results, and the execution will still run on the server. AJAX provides a new intermediate option to leverage server-based applications while maintaining timely responsiveness and flexibility.

Ajax relies on the server as an intermediary to distribute and process requests. To do this, the. NET encapsulation class relies on the client's request object, and the XMLHttpRequest object is supported by most browsers, so using this object is a good solution.

Therefore, in order to achieve not refreshing the page, our client page is made into a static page. Static pages call a method of the. NET class through Ajax.NET. This is the most concise and efficient solution.

Second, how to apply Ajax.NET

1. Introduction of Ajax.dll documents in the project.

Ajax.dll is a class library file developed by Microsoft for use in asp.net. This class library encapsulates the implementation details of the XMLHttpRequest request server and is the solution technology of AJAX Knowledge application on the ASP.net platform. In a. NET project, you add a reference to it, and then you can start using the Ajax.dll package for development.

2. Set up Httphandle in Web.config

In order for it to work, the first step must be to install the Httphandle package in Web.config, not to explain in detail how httphandle works, we just need to understand that they can be used to process asp.net requests. For example, all requests for *.aspx can be sent through the System.Web.UI.PageHandlerFactory class to the control handle, simply saying, we put anything toward ajax/*. ASHX requests are sent to the Ajax.pagehandlerfactory request processing handle.

3. Writing service-side functions

Now we write server-side functions that can be invoked asynchronously by the client. Although it is not yet possible to support all of the return types, we still adhere to the server-side add functionality. In the page class of the Codebehind file, add the following method:

[Ajax.AjaxMethod()]
public int ServerSideAdd(int firstNumber, int secondNumber)
{
 return firstNumber + secondNumber;
}

Note that this function has a ajax.ajaxmethod () custom attribute, and the property service tells the Ajax wrapper class to create a JavaScript proxy for this method so that it can be invoked by the client.

Related Article

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.