First try new. Net Ajax refreshing Technology

Source: Internet
Author: User
I have heard of Ajax technology for a long time. It is a very good thing in the legend. It is called "refreshing". In fact, it uses JavaScript on the web and uses asynchronous XMLHTTP requests to implement a refreshing web interface. Unfortunately, I have never experienced it. My friends who have heard of PHP have used the PHP Ajax development kit, and have done a lot of cool things, which makes me envy.

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. You can use this function to test the function knowledge. You can also write a simple function to replace it.
{
String Mac =   "" ;

System. Diagnostics. Process =   New System. Diagnostics. Process ();
Process. startinfo. filename =   " NBTSTAT " ;
Process. startinfo. Arguments =   " - " + 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,FunctionGetmac ()
{
 VaRClientip="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

Add onclick = "javascript: getmac ()" to the onclick event of input ()"

<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

(2007-6-23)ArticleModify: the current version of the subsequent step 7th is no longer needed. It was written in this blog for 05 years and has changed a lot. We recommend that you use ajaxpro,
Download demo

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 " ;< BR >}< P>

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

note the following. net Ajax needs to be manually performed in the global. add ajax to asax. utility. handlerpath = "ajax"; configuration file web. the httphandler configuration information must be added to config!

the new version of the Development Kit has not been ready for trial. It is estimated that the new version is more convenient and may remove the manual setting of global. add ajax to the asax application_start event. utility. handlerpath = "ajax"; and other troublesome settings! Looking forward to ing ......

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.