Ajax.NET Library version 5.5.10.1
I fixed the ArrayList and custom class problem. The C# example has been changed to make a test method for arrays (ArrayList, StringCollection, []). There is also a test for a custom class. (Note: currently there is no support for classes that inherit from CollectionBase, I will have to check how to do this in JSON.)
Update: You have to mark your own classes with the [Serializable] attribute. See the example at the download website.
Download available for free at http://ajax.schwarz-interactive.de
14 Comments
Comments have been disabled for this content.
Anders Wåglund said
Great!
It is working as expected now. I really love the ability to wait for events.
Günther said
Great work Michael, the ArrayList with custom classes is working now.
Anders: could you give an example of waiting for events? If you wanted to create a web page with a news ticker and have that updated say every 2 second. Would this be possible without having a javascript timer polling the server?
scott e said
Hey Michael,
Here's an example of a class I'm returning to the client:
<Serializable()> _
Public Class Appointment
Implements IComparable
Dim _ScheduleID As Integer = -1
Dim _StartTime As DateTime = Now
Dim _EndTime As DateTime = Now
Dim _PatientComments As String = ""
<snip>
I set these variables with public properties when I get data from the DB (I'm using DotNetNuke for this).
Anyhow, when I try to hit return this class with the new .dll, I get an error that states that an } is missing... If I debug to it, it's getting the data OK, but something in the .dll is not liking the class data.
As I mentioned before, all of this worked swell with the version from a few days ago...
I have restarted/cleared cache/cleared vswebcache, and recompiled all of my projects.
Weird, eh?
Thanks,
se
Michael Schwarz said
@Scott: I have build an example with your code:
<Serializable()> Public Class Appointment
Implements IComparable
Dim _ScheduleID As Integer = -1
Dim _StartTime As DateTime = Now
Dim _EndTime As DateTime = Now
Dim _PatientComments As String = ""
Public ReadOnly Property PatientComments() As String
Get
Return _PatientComments
End Get
End Property
Public ReadOnly Property EndTime() As DateTime
Get
Return _EndTime
End Get
End Property
Public ReadOnly Property StartTime() As DateTime
Get
Return _StartTime
End Get
End Property
Public ReadOnly Property ScheduleID() As Integer
Get
Return _ScheduleID
End Get
End Property
Public Overloads Function CompareTo(ByVal obj As Object) As Integer _
Implements IComparable.CompareTo
If TypeOf obj Is Appointment Then
Return True
End If
Throw New ArgumentException("object is not a Appointment")
End Function
End Class
The Ajax.NET method in VB.NET:
<Ajax.AjaxMethod()> Public Function Test13() As Appointment
Dim _a As Appointment
_a = New Appointment
Return _a
End Function
So, it is working for me. Can you send me more detailed information what you are doing. Perhaps you can send me the complete code for the Appointment class and the Ajax.NET method.
scott e said
Hi Michael,
Right on -- I'm trying to understand why it's not working here... It turns out that the first method sent to the server works find. That's the Appt class. Then I have a Patient Class coming through next. It's no different than the other one. It crashes with a System.StackOverflowException, then the server crashes. I have to restart IIS.
So... I was thinking I had some sort of versioning problem, but I don't think that's the case... I have cleared all the caches out and all that.
BTW, the callstack is filled with a ton of stuff, but it's primarially calls to PropsFieldsToJSON(). Maybe you could trap a max loop number and create a custom error...
thanks,
se
Michael Schwarz said
@Scott: Can you please send me more details of the patient class? I know that if there is a child-parent reference it will generate a StockOverflowException.
Olli said
GREAT SOFTWARE!! Michael. thanks for the last changes, that is excellent work!!! What will be the next steps you want to implement?
scott e said
Hi Michael,
The Patient and Appt classes don't have any sort of relationship to each other, and they are simple classes -- neither has anything but primitives and datetime objects.
The Appt class is filled first, sent asynchronously back to client. Then, the client fires another function to load the Appt asynchronously to another function, so they are totally isolated.
Funny that it works fine in the previous version... I wish I could help you more with it...
Thanks,
se
Syed Aziz ur Rahman said
Great work. Now my serializable custom classes are working finally. The features of arraylist is also good. I have tried and it is working great.
scott e said
Hi Michael,
I have figured out the last problem I had -- I had a GUID type in there... Now, I am having problems with this class:
<Serializable()> _
Public Class Billing
Implements IComparable
Dim _BillingID As Integer = -1
Dim _PatientID As Integer = -1
Dim _PatientName As String = ""
Dim _AppointmentID As Integer = -1
Dim _TotalPrice As Decimal = 0D
Dim _TotalPaid As Decimal = 0D
Dim _IsPaidInFull As Boolean = False
Dim _Notes As String = ""
Dim _DateSubmitted As DateTime = Now
Dim _DateUpdated As DateTime = Now
Dim _SortOrder As String
<snip properties>
... I am thinking that it's the Decimal type -- it's the first decimal type I've tried to send over with this library. The method fills an arraylist with 2 of these objects. The TotalPrice and TotalPaid both have 0 in them for each record.
here's the function I use:
<Ajax.AjaxMethod()> _
Public Function getBills_ForSchedule(ByVal ScheduleID As Integer) As ArrayList
Return BillDB.GetBills_ForSchedule(ScheduleID)
End Function
scott e said
Sweet! Thanks a lot.
Josh Pollard said
Can someone please post a complete solution as to how to use this? All of the downloadable samples and instruction documents look to be pretty out-dated. I just want something simple.
Como fazer um currículo said
The only outdated information in the .DOC is to use
[Ajax.AjaxMethod()]
instead of
[Ajax.JavascriptMethod()]
Shindigo said
I am getting "TypeError - 'MyPage_aspx' is undefined" from javascript when I try to make the 'MyPage_aspx.MyMethod' call to the server.
Hmm... Should I be using [Ajax.JavascriptMethod()] attribute instead of [Ajax.AjaxMethod()] ?
I tried it and the compiler complains that JavascriptMethod is not defined. I'm not sure what to do now.
TIA for any help - shindigo AT gmail