In today's project, because it needs to be triggered asynchronously, when the text box loses focus, it goes to the database to check once, and then I thought of three ways.
A brief introduction to its usage:
1. Use of AjaxPro
1. Add Quote, browse to find the AjaxPro.2.dll file
2. Write the following code in system.web in Web.config
/configuration>
3. In Loading event , add
AjaxPro.Utility.RegisterTypeForAjax(typeof(class name));
4. All methods written must start with
[AjaxPro.AjaxMethod], and then write the method
5. You must write clearly when calling
Namespace Name.Class name.Method, for example: WebUI._Default.getData();
6. The call can be divided into two Method (synchronous call, asynchronous call)
//No parameter method written in the background
[AjaxPro.AjaxMethod]
public string getStr()
{
return "hello my friends";
}
//Method with parameters written in the background
[AjaxPro.AjaxMethod]
public string getString(string str)
{
return str + "Say: hello my friends";
}
a. Synchronous call
(1). Drag into the html controlbutton
(2). Double-click and it will automatically display in. In the aspx script
(3). Write the content you want to enter
Example:
//------------------Synchronous call No parameters -----------
function Button1_onclick()
{
var res=WebUI._Default.getStr();
alert(res.value);
}
//------------------Synchronous call has parameters------------
function Button2_onclick( ) //TextBox1 is a server control
{
var str=document.getElementById("").value;
var res=WebUI._Default.getStr(str );
alert(res.value);
}
b. Asynchronous call
(1). Drag into the html control button
(2). Double-click and it will automatically display in In the .aspx script
(3).Write the content you want to enter
Example:
//-----------------Asynchronous call No parameters-----------------
function Button3_onclick() {
WebUI._Default.getStr(getStrCallBack);
}
function getStrCallBack(res )
{
alert(res.value);
}
//-----------------Asynchronous call has parameters----- ------------
function Button4_onclick() {
var str=document.getElementById("").value;
WebUI ._Default.getString(str,getStringCallBack);
}
function getStringCallBack(res)
{
alert(res.value);
}
7.CallObject
//Object
[AjaxPro.AjaxMethod]
public Class getClass()
{
Class cla = new Class();
cla .C_Id = 100;
cla.C_Name = "Class 34";
cla.Count = 20;
return cla;
}
//--------- ---------Synchronous call object-----------
function Button5_onclick() {
var res=WebUI._Default.getClass().value;
alert("Class number:"+res.C_Id+"Name:"+res.C_Name+"Number of people:"+res.Count);
}
//---------------- ------Asynchronous call object-----------
function Button6_onclick() {
WebUI._Default.getClass(getClassCallBack);
}
function getClassCallBack( clas)
{
var res=clas.value;
alert("Class number: "+res.C_Id+" Name: "+res.C_Name+" Number of people: "+res.Count);
}
8.Use of data set
//Method
[AjaxPro.AjaxMethod]
public DataSet getInfo()
{
return WebUI.GetDataSet.getList();
}
//--------------------Asynchronously call the data set------ --------
function Button8_onclick() {
WebUI._Default.getInfo(getDataSetCallBack);
}
function getDataSetCallBack(res)
{
var dataset= res.value;
var strHtml="";
strHtml +='
学生编号 | ';名称 | ';年龄 | ';
'+ dataset.Tables[0].Rows[i].stu_id +' | ';'+ dataset.Tables[0].Rows[i].stu_name +' | ';'+ dataset.Tables[0].Rows[i].stu_age +' | ';
thedata.innerHTML=strHtml;//thedata是一个中的thedata
}
9.验证码的使用
//----------------------验证码的使用(必须采用同步调用)----------------------
//验证码的使用
[AjaxPro.AjaxMethod]
public bool ValidCodeData(string code)
{
return (HttpContext.Current.Session["CheckCode"].ToString()==code);
}
function Button9_onclick() {
var code=document.getElementById("").value;
var bool=WebUI._Default.ValidCodeData(code).value;
if(bool==true)
{
alert("ok");
}else
{
alert("no");
}
}
AjaxPro.dll文件网上很多的,自己下,如果找不到呢,给我发个留言,我发你邮箱
二,直接调用:
javascript中:
function says()
{
alert("");
}
function del()
{
alert("");//DeleteByID(8)后台方法名
}
三,采用ICallbackEventHandler回调
/**//*
* Declare the ICallbackEventHandler interface . To call the server code on the client without postback, you must declare the interface and implement its two methods:
* RaiseCallbackEvent( ), GetCallbackResult()
* The parameters of RaiseCallbackEvent() are passed from the front desk. Different codes are executed according to the passed parameters and the results are returned to the front desk with GetCallbackResult()
*/
//必须声明System.Web.UI.ICallbackEventHandler接口
public partial class _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
//定义一个回调的返回值
private string Result;
//定义两个变量,用来接收页面传过来到操作数
private string Num1;
private string Num2;
protected void Page_Load(object sender, EventArgs e)
{
}
/**////
/// 该方法是回调执行的方法,根据参数在这个方法中处理回调的内容,该方法没有返回值
///
/// 此参数是从客户端传过来的
public void RaiseCallbackEvent(string eventArgument)
{
//eventArgumeng is the parameter passed by javascript from the client. In this example, the three parameters are passed and separated by "/". Each parameter is taken out and stored in the array
string[] PagParams = eventArgument.Split( '/');
Num1 = PagParams[1];
Num2 = PagParams[2];
//According to the first parameter (selected operator), call Different execution function
# Switch (pagparams [0])
{## case "0":
result = add (); ## case "1" :
Result = sub(); break;
case "2":
Result = multi(); break;
case "3":
Result = pision(); break;
}
}
/**////
/// This method returns the result of the callback to the client
/// summary>
///
public string GetCallbackResult()
{
return Result;
}
//Four at a time The function is the function that calls the callback to perform the operation through the RaiseCallbackEvent method
private string add()
{
double addResult = double.Parse(Num1) + double.Parse(Num2);
return addResult.ToString();
}
private string sub()
{
double addResult = double.Parse(Num1) - double.Parse(Num2);
return addResult .ToString();
}
private string multi()
{
double addResult = double.Parse(Num1) * double.Parse(Num2);
return addResult. ToString();
}
private string pision()
{
double addresult = double.Parse(Num1) / double.Parse(Num2);
return addresult.ToString ();
}
}

The above is the detailed content of asp.net asynchronous trigger usage (AJAX). For more information, please follow other related articles on the PHP Chinese website!

The combination of C# and .NET provides developers with a powerful programming environment. 1) C# supports polymorphism and asynchronous programming, 2) .NET provides cross-platform capabilities and concurrent processing mechanisms, which makes them widely used in desktop, web and mobile application development.

.NETFramework is a software framework, and C# is a programming language. 1..NETFramework provides libraries and services, supporting desktop, web and mobile application development. 2.C# is designed for .NETFramework and supports modern programming functions. 3..NETFramework manages code execution through CLR, and the C# code is compiled into IL and runs by CLR. 4. Use .NETFramework to quickly develop applications, and C# provides advanced functions such as LINQ. 5. Common errors include type conversion and asynchronous programming deadlocks. VisualStudio tools are required for debugging.

C# is a modern, object-oriented programming language developed by Microsoft, and .NET is a development framework provided by Microsoft. C# combines the performance of C and the simplicity of Java, and is suitable for building various applications. The .NET framework supports multiple languages, provides garbage collection mechanisms, and simplifies memory management.

C# and .NET runtime work closely together to empower developers to efficient, powerful and cross-platform development capabilities. 1) C# is a type-safe and object-oriented programming language designed to integrate seamlessly with the .NET framework. 2) The .NET runtime manages the execution of C# code, provides garbage collection, type safety and other services, and ensures efficient and cross-platform operation.

To start C#.NET development, you need to: 1. Understand the basic knowledge of C# and the core concepts of the .NET framework; 2. Master the basic concepts of variables, data types, control structures, functions and classes; 3. Learn advanced features of C#, such as LINQ and asynchronous programming; 4. Be familiar with debugging techniques and performance optimization methods for common errors. With these steps, you can gradually penetrate the world of C#.NET and write efficient applications.

The relationship between C# and .NET is inseparable, but they are not the same thing. C# is a programming language, while .NET is a development platform. C# is used to write code, compile into .NET's intermediate language (IL), and executed by the .NET runtime (CLR).

C#.NET is still important because it provides powerful tools and libraries that support multiple application development. 1) C# combines .NET framework to make development efficient and convenient. 2) C#'s type safety and garbage collection mechanism enhance its advantages. 3) .NET provides a cross-platform running environment and rich APIs, improving development flexibility.

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor