Ajax.NET and enums, XmlDocument,...

With the free Ajax.NET Library you can use enums, now. I will export the value as an string:

  enum MyType{ Unkown, Starting, Stopped, Killed }
 
MyType x = MyType.Starting;   // this will return "Starting" on the client-side

I also fixed the XmlDocument return value. You will have a XML DOM object on the client to parse this XML (this will be different in Internet Explorer and FireFox!!). If you want to get the XML as an string you can use .request.responseText instead of .value.

To use an HtmlControl as an argument has been fixed, also. There was a wrong client-side script that didn't send the complete control to the server. Cache support can be used together with changing the method name or specifiying the sessionstate support.

You can download the version 5.6.3.4 from my private web page http://ajax.schwarz-interactive.de/.

Published Friday, June 03, 2005 8:56 PM by Michael Schwarz

Comments

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 03, 2005 2:59 PM by Robert McLaws
You might consider changing your versioning scheme so where your last digit is actually the build date. If you released a build today, it would be something like 5.6.4.50603, where 5=2005, 06=Month, 03=Day. Would make life easier understanding when the builds were put out.

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 03, 2005 3:05 PM by Michael Schwarz
I was using Year.Month.Day.VersionOnThisDay.

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 03, 2005 4:07 PM by Michael Third
You can ask me to leave whenever you feel like it, but I have another request :-)

Our company has several zones that the client can request a WebMethod from. It would seem to make sense to allow the JavaScript consumer to specify a baseUrl ala:

AjaxMethodHandler.baseUrl = "server1.my.net";
AjaxMethodHandler.Go();

AjaxMethodHandler.baseUrl = "server2.my.net";
AjaxMethodHandler.Go();

I've made a workaround by saving off "this.url" and changing it inside a loop, but its rather kludgy. You could even make this optional by having this.baseUrl = "".

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 03, 2005 4:09 PM by Michael Third
Another request, what about implementing a simple method where one app server could call an Ajax method on another app server? I could code this up and submit it if you would like.

Michael

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 03, 2005 4:19 PM by AndrewSeven
I found it a little odd that I needed to specify .value on the return value of a function.

alert(MyPage.ServerSideAdd(100,99).value)
instead of
alert(MyPage.ServerSideAdd(100,99))

Is there a specific reason for this choice?

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 03, 2005 5:23 PM by Michael Schwarz
@Andrew: yes, it is because I would not use the sync methods. I use the async call with the callback handler to prevent the browser from blocking while the method is running.

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 03, 2005 6:14 PM by AndrewSeven
Yes but from the view of the script block where I call alert, the operation sure seems synchronous. I call it and I get the result object back.

I gave AJAX a quick try today :) , I'll have a bit closer look on Monday

# KISS AJAX :)

Sunday, June 05, 2005 7:35 AM by TrackBack

# re: Ajax.NET and enums, XmlDocument,...

Monday, June 06, 2005 3:20 AM by AndersH
On the client maybe it would be nicer to have the xml represented as a javascript associative array (maybe in the stryle that Perls XML::Simple create). That would make the code cross platform.

# re: Ajax.NET and enums, XmlDocument,...

Tuesday, June 07, 2005 10:33 AM by Passing Client Side String Arrays in to Ajax Funct
I cannot pass Client Side String Arrays in to an Ajax Function in a
cs file. I am not sure what the problem is. I can pass an int Array into the Ajax function with no problems and I can pass pass the Client Side String Arrays as multiple string parameters into the server side function. Is this a Bug?

# re: Ajax.NET and enums, XmlDocument,...

Tuesday, June 07, 2005 2:56 PM by Michael Schwarz
Can you please give me the method body? You should use

public void MyMethod(string[] args)

# re: Ajax.NET and enums, XmlDocument,...

Tuesday, June 07, 2005 3:29 PM by Ayehou M.

Trying to pass the following array on the client side Array("A,B","C") would end up as ["A","B","C"] on the serverside. Can anyone help me come to some kind of understanding. Is it supposed to be this way, or is this a bug?

Further, why are double quotes (") escaped to \"?

# re: Ajax.NET and enums, XmlDocument,...

Wednesday, June 08, 2005 12:01 AM by Ayehou M.
Is there a forum where one can post questions and get them answered?

# re: Ajax.NET and enums, XmlDocument,...

Wednesday, June 08, 2005 4:05 AM by Michael Schwarz
@Ayehou: Not yet, I am working on that. Please send your questions using the contact form on this web page.

# re: Ajax.NET and enums, XmlDocument,...

Wednesday, June 08, 2005 8:11 AM by Andersh
Ayehou M., I commented on this (or maybe just simelair) issue here: http://weblogs.asp.net/mschwarz/archive/2005/05/13/406751.aspx#408291

But I can not recreate you issule with this at the demo-page: javascript:alert(DemoMethods.Test18( new Array("A,B","C")).value);
Have I misunderstood you?

# re: Ajax.NET and enums, XmlDocument,...

Wednesday, June 08, 2005 2:54 PM by Ayehou M.
Right, no, you are actually right.
What I assumed was, since I failed with a bit more involved case of what
I taught of the same class of problem, I really assumed the example I
submited would fail too. But as you said that one executes ok. So
let me bring forward my example:

the ajax code on the server is:
<Ajax.AjaxMethod()> Public Function ArrayLength(ByVal indata() As String) As Integer
return indata.Length
End Function


the client code is as follows:
<script language="javascript">
function GetLength()
{
var j = new Array(document.getElementById("j1").innerHTML);
var jResult = join.ArrayLength(j);
document.getElementById("result").innerText = jResult.value;
}
function Scream(a,b){ alert(a);alert(b); }
</script>



the html is as follows:

<span id="j1"><img src="img\en.gif" onmouseover="Scream('aaa','bbb')"></span><br>
Result:<span id="result"></span><br>
<a href="#" onclick="GetLength();">GetLength</a>


Hope you can help me out on this.

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 10, 2005 7:10 AM by AndersH
Ayeheo M.: I belive that it is the same problem, that you see. You don't write what results you get or what you expect to see, but I made this test, from your example (it all goes on one line):
javascript:void(s="<img src=\"img\\en.gif\" onmouseover=\"Scream('aaa','bbb')\">");alert("Input:"+s+"\nExpected: <p>"+s+"</p>\nActual: "+DemoMethods.Test18([s]).value);

It shows that the string in the singleton array is spilt on the comma, the first an last chars is removed (e.i. the double and sigle quotes from the first part of the string and the single and double quotes from the last part of the string) and the string is not decoded.

I belive the problem would be removed by using the proposed FromJSArray function (but a move to using a url-encoding would be better, I think). In the mean time you might consider url-encoding the parameters (using the escape-function) on the clientside and decoding them on the server side or avoid using double quotes in the strings (ie. write <span id="j1"><img src='img/en.gif' onmouseover='Scream('aaa','bbb')'></span><br>) which might work.

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 10, 2005 7:12 AM by AndersH
Hmm... encoding isn't quite working on this board either. The last example should read: <span id="j1"><img src='img/en.gif' onmouseover='Scream(&amp;#39;aaa&amp;#39;,&amp;#39;bbb&amp;#39;)'></span><br>

# re: Ajax.NET and enums, XmlDocument,...

Friday, June 10, 2005 7:14 AM by AndersH
Na, thats not right either. I can't figure out the logic behind this. I hope you get the idea.