Based on. NET three kinds of Ajax technology: Native JS, asp.net ajax and. NET Callback technology

Source: Internet
Author: User

In asp.net development, we need to use more and more Ajax technology to enrich the user interaction interface, and constantly improve the user experience.

The first way is for us to manually write JavaScript code implementations, in this way I've introduced a blog post, "Join me in creating a simple JavaScript Ajax object." Concrete implementation here no longer repeat. One of the great benefits of using this approach is that it allows us to grasp the entire process of asynchronous communication ourselves, but requires a developer to have a good JavaScript base, and another point is to create a new Handler.ashx file or an ASPX file.

Microsoft has always liked to lower the entry threshold for development, so. NET2.0 then released their asp.net ajax framework, which allows us to implement Ajax with a simple drag-and-drop control like development WebForm, which leads to an example. The ASPX page code is as follows

 <form id= "Form1" runat= "Server" > <div> <asp:scriptmanager id= "ScriptManager1" runat= "Server" > </asp:ScriptManager> <p> <asp:label id= "Lblnonajax" runat= "Server" text= "No Ajax" ></ asp:label> </p> 

Although we did not make any changes to the ScriptManager control, the control does not display any information, but we have to use the AJAX framework to drag and drop the control before the other Ajax controls. Then the most we use is the UpdatePanel control, and the control is really exciting. We can specify those events in the control that require local refresh and full page refresh, and asynchronous local refreshes by default. If you want to achieve full page refresh submission, as usual without the effect of Ajax controls, simply specify the <asp:postbacktrigger controlid= "Btnnonajax"/> in the <Triggers> tag; ControlID is a control that does not need to be committed asynchronously, so that any event for that control is specified as a full page refresh commit.

Next look at CS code as follows

Public partial class _default:system.web.ui.page {protected void Page_Load (object sender, EventArgs e) {if (IsPostBack) {//Because the following controls are not in update, the Ajax event cannot be updated when it is triggered) l Blnonajax.text = "Triggers the postback event!"
            "; } protected void Btnajax_click (object sender, EventArgs e) {This.lblText.Text
    
            = "This is the trigger of an AJAX event";   
            Response.Write ("<script>alert (' This is an AJAX Event trigger ') </script>"); Triggers an AJAX event that cannot be exported to the page in that way or otherwise, unless the UpdatePanel control event is triggered by using the following method, the output script must use the following methods Scriptmanager.re Gisterstartupscript (this. UpdatePanel1, this.
        GetType (), "Ajaxscript", "alert (' This is the trigger of an AJAX event ');", true); } protected void Btnnonajax_click (object sender, EventArgs e) {This.lblText.Text = "This is a
            Page postback Refresh Event trigger ";
        Response.Write ("<script>alert (' This is a page postback refresh Event trigger ') </script>");
 }   } 

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.