Asp.net ajaxpro background data asynchronous processing method analysis (1/2)

Source: Internet
Author: User

Asp tutorial. net ajaxpro background processing data asynchronous processing method parsing
I. Use of AjaxPro


1. Add references to the project and browse to the AjaxPro.2.dll file.

2. Write the following code in system. Web in web. config:
</Configuration>

<System. web>
<HttpHandlers>
<Add verb = "*" path = "*. ashx" type = "AjaxPro. AjaxHandlerFactory, AjaxPro.2"/>
</HttpHandlers>
</System. web>
<// Configuration>

3. Add
AjaxPro. Utility. RegisterTypeForAjax (typeof (class name ));

4. All write methods must be used.
[AjaxPro. AjaxMethod]

5. Make it clear when calling
Namespace name. Class name. Method, for example, WebUI. _ Default. getData ();

6. The call can be divided into two methods (synchronous call and Asynchronous call)

// No parameter method written in the background
[AjaxPro. AjaxMethod]
Public string getStr ()
{
Return "hello my friends ";
}
// The 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 the html control button
(2) double-click to automatically display it in the. aspx script.
(3). Write the content you want to enter in it
Example:
// ------------------ Synchronous call without parameter -----------
Function Button1_onclick ()
  {
Var res = WebUI. _ Default. getStr ();
Alert (res. value );
  }
 
// ------------------ Synchronous call with parameter ------------
Function Button2_onclick () // TextBox1 is the server control
{
Var str = document. getElementById ("<% = TextBox1.ClientID %>"). value;
Var res = WebUI. _ Default. getStr (str );
Alert (res. value );
}


B. Asynchronous call
(1) drag the html control button
(2) double-click to automatically display it in the. aspx script.
(3). Write the content you want to enter in it
Example:

// ----------------- Asynchronous call without parameter -----------------
Function Button3_onclick (){
WebUI. _ Default. getStr (getStrCallBack );
}
Function getStrCallBack (res)
{
Alert (res. value );
}
// ----------------- Asynchronous call with parameter -----------------
Function Button4_onclick (){
Var str = document. getElementById ("<% = TextBox1.ClientID %>"). value;
WebUI. _ Default. getString (str, getStringCallBack );
}
Function getStringCallBack (res)
{
Alert (res. value );
}

7. Call object

// Object

[AjaxPro. AjaxMethod]
Public Class getClass ()
{
Class linoleic = new Class ();
Linoleic. C_Id = 100;
Linoleic. C_Name = "Class 34 ";
Linoleic. Count = 20;
Return linoleic;
}
// ------------------ Synchronous call object -----------
Function Button5_onclick (){
Var res = WebUI. _ Default. getClass (). value;
Alert ("Class No.:" + res. C_Id + "name:" + res. C_Name + "student Count:" + res. Count );
}
// ------------------ Asynchronous call object -----------
Function Button6_onclick (){
WebUI. _ Default. getClass (getClassCallBack );
}
Function getClassCallBack (clas)
{
Var res = clas. value;
Alert ("Class No.:" + res. C_Id + "name:" + res. C_Name + "student Count:" + res. Count );
}


8. Use of datasets

// Method
[AjaxPro. AjaxMethod]
Public DataSet getInfo ()
        {
Return WebUI. GetDataSet. getList ();
        }

// -------------------- Asynchronously call the dataset --------------
Function Button8_onclick (){
WebUI. _ Default. getInfo (getDataSetCallBack );
}
Function getDataSetCallBack (res)
{
Var dataset = res. value;
Var strHtml = "";
StrHtml + = '<table style = "border-collaps tutorial e: collapse; border-color: Gray;" border = "1px"> ';
StrHtml + = '<tr> ';
StrHtml + = '<td> Student ID </td> ';
StrHtml + = '<td> Name </td> ';
StrHtml + = '<td> age </td> ';
StrHtml + = '</tr> ';
   
For (var I = 0; I <dataset. Tables [0]. Rows. length; I ++)
    {
StrHtml + = '<tr> ';
StrHtml + = '<td>' + dataset. Tables [0]. Rows [I]. stu_id + '</td> ';
StrHtml + = '<td>' + dataset. Tables [0]. Rows [I]. stu_name + '</td> ';
StrHtml + = '<td>' + dataset. Tables [0]. Rows [I]. stu_age + '</td> ';
StrHtml + = '</tr> ';
    }
StrHtml + = '</table> ';
Thedata. innerHTML = strHtml; // thedata is thedata in <div id = "thedata"> </div>
}

 

9. Use of the verification code

// ---------------------- Use of the verification code (synchronous call is required )----------------------

// Use the verification code

[AjaxPro. AjaxMethod]
Public bool ValidCodeData (string code)
{
Return (HttpContext. Current. Session ["CheckCode"]. ToString () = code );
}

Function Button9_onclick (){
Var code = document. getElementById ("<% = TextBox2.ClientID %>"). value;
Var bool = WebUI. _ Default. ValidCodeData (code). value;
If (bool = true)
    {
Alert ("OK ");
} Else
    {
Alert ("no ");
    }
}

2. Direct call:

Webpage effect: <% = background method %>
Function says ()
    {
Alert ("<% = Say () %> ");
    }
Function del ()
    {
Alert ("<% = DeleteByID (8) %>"); // ebyid (8) background method name}

Homepage 1 2 Last page
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.