Basic example of ajaxpro for. net

Source: Internet
Author: User
Basic example of ajaxpro for. net

Here I will not elaborate on AJAX anything else, with a DLL, address such as right: www.schwarz-interactive.de directly on the example

1. Here, the environment is vs2005, and ajaxpro.2.dll is used to create an Asp.net project named ajaxprodemo. Reference ajaxpro.2.dll to the project (put it in the bin folder and put it in the crap !)

2. Save and run it. The web. config file is generated. You cannot figure out why 2005 matches a web. config file when the project is not created ......

3. Add the following paragraph to the generated web. config: <system. Web>
<Httphandlers>
<Add verb = "post, get" Path = "ajaxprodemo/*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro.2"/>
</Httphandlers> All ajaxpro/*. ashx requests are processed by Ajax. pagehandlerfactory, rather than by the default system. Web. UI. pagehandlerfactory processing factory.

4. Compile server-side Ajax functions:

The only difference between him and the common server method is that he must add [ajaxpro. ajaxmethod] to the method.

Add the following code to the default. aspx page (almost all basic Ajax examples start with addition [ajaxpro. ajaxmethod]
Public String addtwo (INT firstint, int secondint)
{
Return convert. tostring (firstint + secondint );
}

5. After writing Step 4, register the class in page_load.

Protected void page_load (Object sender, eventargs E)
{
Ajaxpro. Utility. registertypeforajax (typeof (_ default ));
}

6. Write the front-end code of default ..

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> ajaxprousedll </title>
<Script language = "JavaScript" type = "text/JavaScript">
Function addint ()
{
VaR I1 = Document. getelementbyid ('t1'). value;
VaR I2 = Document. getelementbyid ('t2'). value;
Document. getelementbyid ('b2'). value = _ default. addtwo (I1, I2). value;
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Input type = "text" id = "T1"/> + <input type = "text" id = "T2"/>=< input type = "button" id =" b2 "value =" sum "onclick =" addint () "/>
</Div>
</Form>
</Body>
</Html>

Here we put two text boxes and a button to call the addtwo method of the server when you click it ..., note that the returned value is required. value (all HTML controls are used here. Do not add the server control)

7. Create a global. asax page in the project... (This is a waste of half an hour to solve the problem.) add ajaxpro. Utility. handlerpath = "ajaxprodemo" to the application_start event. If nothing happens, run the program... Enter the number point button to get the result of adding... It should be noted that this ajaxpro can also be run in vs2003, but the referenced DLL is ajaxpro. DLL. In addition, 2003, there is a namespace by default. At this time, you need to change it to inherits = "[Your namespace name] at the top of the page. _ default ". Later, when the server is called in JS, It is not _ default. addint (). value, which must be changed to [Your namespace name]. _ default. addint (). value (the default namespace does not exist in the strange 2005, but it can be added if necessary)

 

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.