Ajax Basic Configuration Usage Tutorial

Source: Internet
Author: User
Tags add string visual studio
ajax| Tutorial Ajax is defined as the abbreviation for "Asynchronous JavaScript + xml", which is asynchronous JavaScript and XML processing. In principle, the main is Ajax can be called HttpRequest to implement asynchronous communication with the server, and ultimately in the Web page to achieve a rich and user-friendly user interface
Ajax use preliminary, configuration steps
1. Ajax.dll copy to the application system Bin directory, and then refer to Ajax.dll in the project reference, if not, you can download /files/singlepine/ajax.rar
2. Configure Web.config and add the following information
<add verb= "Post,get" path= "Ajax/*.ashx" type= "Ajax.pagehandlerfactory, Ajax"/>
3. Assuming the application system is called document, the directory format is pages\ajaxtest
4. Establish the CS file AjaxMethod.cs under Pages\ajaxtest, add the following method
[Ajax.ajaxmethod]
[Ajax.ajaxmethod (Ajax.HttpSessionStateRequirement.Read)]
public static string Getnivnumber (String str)
{
return str;
} 5. Create a page under Pages\ajaxtest ajaxform.aspx
<HTML>
<HEAD>
<title>AjaxForm</title>
<meta name= "generator" content= "Microsoft Visual Studio. NET 7.1" >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
<script language= "JavaScript" >
function Testajax (owner, item, EVT)
{
var First=document.getelementbyid ("Txtfirst");
Ajaxmethod.getnivnumber (First.value,callback_getnivnumber);
}
function Callback_getnivnumber (res)
{
var Obj=document.getelementbyid ("Txtsecond");
Obj.value=res.value;
}
</script>
</HEAD>
<body ms_positioning= "GridLayout" >
<form id= "Form1" method= "POST" runat= "Server" >
<input style= "Z-INDEX:101; left:208px; Position:absolute; top:40px "type=" button "value=" button "
Onclick= "Testajax ();" >
<asp:textbox id= "Txtfirst" style= "z-index:102; left:40px; Position:absolute; top:40px "runat=" Server ></asp:TextBox>
<asp:textbox id= "Txtsecond" style= "z-index:103; left:40px; Position:absolute; top:72px "runat=" Server ></asp:TextBox>
</form>
</body>
protected System.Web.UI.WebControls.TextBox Txtsecond;
private void Page_Load (object sender, System.EventArgs e)
{
Registers, where Document.Pages.AjaxTest.AjaxMethod is the namespace in which the AjaxMethod.cs method resides
Ajax.Utility.RegisterTypeForAjax (typeof (Document.Pages.AjaxTest.AjaxMethod));
} And then run on it,
Implementation effect: Enter the content in the first textbox, click the button, and display the content in the second textbox. This is just a simple example, and you can modify the calling method, read from the database, and more complex operations

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.