Experience the surprise of the new. Net Ajax refreshing Technology

Source: Internet
Author: User

Today, I got a. Net Ajax development kit, which includes asp2.0 and Ajax currently used in asp1.1. For more information, see http://ajax.schwarz-interactive.de.

1. Create a new project and add reference Ajax. DLL to the reference. Ajax. dll is located in the downloaded package.

2. Create httphandler and add it to Web. config.

<Configuration>

<System. Web>

<Httphandlers>

<Add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/>

</Httphandlers>

<System. Web>

</Configuration>

3. Create a new class demomethods, which can obtain the client MAC address:

Using system;

Using system. Web;

Namespace ajaxsample

{

/** // <Summary>

/// Summary description for methods.

/// </Summary>

Public class demomethods

{

[Ajax. ajaxmethod]

Public String getcustomermac (string clientip) // enter the Client IP address here. This function is used for testing. You can also write other simple functions instead.

{

String MAC = "";

System. Diagnostics. Process = new system. Diagnostics. Process ();

Process. startinfo. filename = "NBTSTAT ";

Process. startinfo. Arguments = "-a" + clientip;

Process. startinfo. useshellexecute = false;

Process. startinfo. createnowindow = true;

Process. startinfo. redirectstandardoutput = true;

Process. Start ();

String output = process. standardoutput. readtoend ();

Int length = output. indexof ("MAC address = ");

If (length> 0)

{

MAC = output. substring (Length + 14, 17 );

}

Process. waitforexit ();

Return Mac. Replace ("-", ""). Trim ();

}

}

}

4. Write JavaScript and create a file named default. js as follows:

Function getmac ()

{

VaR clientip = "192.168.0.1 ";

// Document. getelementbyid ("Mac"). value = demomethods. getcustomermac (clientip). Value

Alert (demomethods. getcustomermac (clientip). value );

}

5. Put an HTML button on An ASPX page

Reference default. js in

<Script language = "JavaScript" src = "Default. js"> </SCRIPT>

Add

Onclick = "javascript: getmac ()"

<Input style = "Z-INDEX: 101; left: 392px; position: absolute; top: 176px" type = "button"

Value = "Client IP" onclick = "javascript: getmac ();">

6. Add

Private void page_load (Object sender, system. eventargs E)

{

// Place user code here to initialize the page

Ajax. Utility. registertypeforajax (typeof (ajaxsample. demomethods ));

}

Note: In typeof (ajaxsample. demomethods), ajaxsample is the namespace, and demomethods is the class to contain the method to be called, that is, step 1 above. Create a class demomethods

7. Modify the application_start event of Global. asax and set the Ajax handlerpath:

Protected void application_start (Object sender, eventargs E)

{

Ajax. Utility. handlerpath = "ajax ";

}

Run the command to check the effect. Is the MAC address of the client obtained on the server without refreshing?

Note that the. NET Ajax version must be manually added with Ajax. Utility. handlerpath = "ajax" in global. asax. The httphandler configuration information must be added to the web. config configuration file!

The new version of this development kit has not been available yet. It is estimated that the new version will be more convenient and may remove manual global settings. add ajax to the asax application_start event. utility. handlerpath = "ajax"; and other troublesome settings!

 

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.