|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionIn Web Forms, we use AJAX to invoke server side methods from the client-side (from JavaScript). AJAX internally uses Performance problems while using AJAXFor each AJAX call, we create an instance of the class which contains the AJAX method. Also, it will create instances for fields, properties, and other class level variables, if we use the Proof of conceptI have created a project which contains two Web Forms, WebForm1.aspx, WebForm2.aspx, and a class, Student.vb. Both code-behind pages have a Note: Webform2.aspx’s '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
Testing the application
For the above test cases, I got logs as below: //Please Note: Some of these log lines
// I have added Manually for explanation purpose.
LOG for the Test Case 1: ( Non Ajax Shared Function )
-------While Loading The Page--------
5/9/2006 10:37:29 AM>>From Student.Constructor
5/9/2006 10:37:29 AM>>From WebForm1.Constructor
5/9/2006 10:37:29 AM>>From WebForm1.Ajax.getData()
-------First Call For GetData()--------
5/9/2006 10:37:29 AM>>From Student.Constructor
5/9/2006 10:37:29 AM>>From WebForm1.Constructor
5/9/2006 10:37:29 AM>>From WebForm1.Ajax.getData()
-------Second Call For GetData()--------
5/9/2006 10:37:29 AM>>From Student.Constructor
5/9/2006 10:37:29 AM>>From WebForm1.Constructor
5/9/2006 10:37:29 AM>>From WebForm1.Ajax.getData()
-------Third Call For GetData()--------
5/9/2006 10:37:30 AM>>From Student.Constructor
5/9/2006 10:37:30 AM>>From WebForm1.Constructor
5/9/2006 10:37:30 AM>>From WebForm1.Ajax.getData()
LOG for the Test Case 2: ( Shared Ajax Function )
-------While Loading The Page--------
5/9/2006 10:37:09 AM>>From Student.Constructor
5/9/2006 10:37:09 AM>>From WebForm2.Constructor
5/9/2006 10:37:09 AM>>From WebForm2.Ajax.getData()
-------First Call For GetData()--------
5/9/2006 10:38:11 AM>>From WebForm2.Ajax.getData()
-------Second Call For GetData()--------
5/9/2006 10:38:11 AM>>From WebForm2.Ajax.getData()
-------Third Call For GetData()--------
5/9/2006 10:38:11 AM>>From WebForm2.Ajax.getData()
In the above logs, we can see that for Test Case 1, we can see more logs which are from the constructors of ConclusionMy suggestion is, in all possible places, we should use the
|
||||||||||||||||||||||