Discussion on an improved method of Ajax performance

Source: Internet
Author: User

First, the introduction

In Web Forms, we use Ajax to invoke the server-side method from the client (through JavaScript), while the XMLHttpRequest call is made inside Ajax. I tested some AJAX functions that were implemented in different ways. In addition, I monitored the performance and lifecycle of Ajax calls. As a result, I found some serious problems with Ajax in Web Forms. However, I have also found a solution to these problems. In this article, I just want to analyze this problem with you and the corresponding solution.

II. performance issues encountered while using AJAX

For each Ajax call, we're going to create an instance of the class that contains the Ajax method. In addition, if we use the New keyword at the class level, we also create instances for the fields, attributes, and other class-level variables.

III. implementation of the programme

I created a project that contains two Web forms: WebForm1.aspx and Webform2.aspx, and a class Student.vb. Both parts of the Code-behind page use an AJAX function GetData () and a student type of public variable. With the help of the Mxlogger class, I recorded the execution process for each phase.

Note: Webform2.aspx's Ajax function GetData () is shared, and in WebForm1 it is not shared.

' Student.vb
Public Class Student
Sub New ()
Mxlogger.addlog ("from Student.constructor")
End Sub
Dim _name as String
Public Property Name () as String
Get
return _name
End Get
Set (ByVal Value as String)
_name = Value
End Set
End Property
End Class
' WebForm1.aspx.vb
Public Class WebForm1
Public Student as New Student
Sub New ()
Mxlogger.addlog ("from Webform1.constructor")
End Sub
<ajax.ajaxmethod (Ajax.HttpSessionStateRequirement.Read) > _
Public Function GetData () as String
Mxlogger.addlog ("from WebForm1.Ajax.getData ()")
Return "I m a Non Shared Function"
End Function
End Class
' WebForm2.aspx.vb
Public Class WebForm2
Public Student as New Student
Sub New ()
Mxlogger.addlog ("from Webform2.constructor")
End Sub
<ajax.ajaxmethod (Ajax.HttpSessionStateRequirement.Read) > _
Public Shared Function GetData () as String
Mxlogger.addlog ("from WebForm2.Ajax.getData ()")
Return "I m a Shared Function"
End Function
End Class

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.