ASP. NET uses Ajaxpro to enable front-end and background interaction

Source: Internet
Author: User

Use Ajaxpro to interact, many people have written articles, why should continue the cliché. Because there are some details we need to pay attention to, because these details if not pay attention to, then the program will error, and poor maintenance.

Introduction

First of all, or that sentence, to practice the martial, will be the first self-palace. The first step in our development process is to build the environment.

Start Visual Studio, my version is 2012 Ah, but this does not affect. First create a Web site project, add the Bin directory to the project, and an Index page.

Then, we need to go online download ajaxpro.2.dll Baidu A bunch of links, here I will not say anything more. The downloaded ajaxpro.2.dll files are then copied or introduced into the Bin directory. Next, write the following in the <system.web> tab of the Web. config .

1 < httphandlers > 2    <  verb= "Post,get"  path= "ajaxpro/*.ashx"  type= " Ajaxpro.ajaxhandlerfactory,ajaxpro.2 "/>3</httphandlers >

And in the server background class, make the following modifications:

1 using Ajaxpro; 2 // (1) 3 4 AjaxPro.Utility.RegisterTypeForAjax (typeof(Index)); 5 // (2) 6 7 [Ajaxpro.ajaxmethod] 8 // (3)

(1): Introducing the Ajaxpro namespace

(2): Registration information to the front page

(3): Each foreground page needs to call the function before adding this

Here I have an example, one thing to note: in the Page_Load () function, a judgment is used. if (page.iscallback) It does this by getting a value that indicates whether the page request is the result of a callback. It's a special callback, so the round trip always happens; however, unlike traditional postbacks, script callbacks do not redraw the entire page. This is in other bloggers crawling, this is the original, but also a small personal programming habits, I do not know what the use, but I just know that useful.

Above, we have built this ajaxpro.2 environment.

Two. Next, the call is started.

1 <%@ Page Language="C #"AutoEventWireup="true"CodeFile="Index.aspx.cs"Inherits="Index" %>2 3 <!DOCTYPE HTML>4 5 <HTMLxmlns= "http://www.w3.org/1999/xhtml">6 <Headrunat= "Server">7 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/>8     <title>Ajaxpro.2.dll</title>9     <Script>Ten          One         functionShow () { A             //(1)         -             varname= Index. GetName (). Value; - Alert ("My Name is:" +name); the  -         } -  -     </Script> + </Head> - <Body> +     <formID= "Form1"runat= "Server"> A     <Div> at         <inputtype= "button"value= "Show"onclick= "Show ()" /> -     </Div> -     </form> - </Body> - </HTML>

  (1) Here, Index is the class name of this class, do not know whether remember. We have written this piece of code AjaxPro.Utility.RegisterTypeForAjax (typeof(Index)); The class name that is declared when the environment is configured. The front-end page also finds our class through this. . Value is also a key point, I remember the first time I used this plugin. Return a Password to determine whether the login success, has always been a failure, this plugin page with log information, I can only one alert finally let me grasp, if there is no value to get a lot of actual applications do not use the information, here need to pay attention.

  1) think this will make the call successful? It's naïve, here we say the first detail: change the managed pipeline mode for a project

Click the mouse button to select this item, and then press F4 to show the properties of this item. Change this property to the traditional type, it's OK. If it is integrated, it will be reported 500.23

2) There is also a point, also a mistake. This error compiles without errors and does not occur when the page is loaded. Only call to Ajaxpro.2 is the time to error uncaught referenceerror:index is not defined when calling the background code does not work, you need to pay attention to whether this is the problem, Because of this error it will not appear on the page and will not be compiled. To see this error, you must press the F12 page to debug, I know that Google Chrome error appears in the Console tab, other browser bloggers are not particularly clear.

The reason for this error, bloggers have also looked up a lot of information, but very few specific description. Here bloggers can only do a blogger's own summary, if someone knows where there is a mistake, I hope you can positively correct (don't be polite, mutual progress ah!!) )。 Blogger analysis, is because of the environment, where there is a problem. build environment bloggers have just said in the previous article is relatively clear, if this error occurs, there should be 70% is the reason.

3) This is also a blogger told me the details Ah! He said so: when calling, you don't have to use the name of the class you're declaring. This class can be renamed using the [ajaxnamespace("DEMO")] tab. The blogger tried it, and it was really possible. Put this tag in front of the class being called, remember it is the class front oh. You can do it.

As you can see, the effect is realized! This label is still very useful.

Thank you very much for watching, but also hope that you have any errors in the above mentioned by bloggers, please comment to tell me. I will verify and revise it in time and hope not to mislead others. Thank you so much!

  

ASP. NET uses Ajaxpro to enable front-end and background interaction

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.