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