IJavaScriptObject in the new version

Michael Schwarz on Friday, October 21, 2005

With the new version you are able to get the real JavaScript wrapper objects that are used internal to representate the JavaScript objects. This will allow you to post any object from the client-side JavaScript code you want that does not exist as a CLR type:

<script type="text/javascript">

function test() { var o = new Object(); o.FirstName = "Michael"; o.Age = 28;

var res = AJAXDemo.WebForm1.GetAnyJavaScriptObject(o);

alert(res.value); }

</script> 

On the server-side code you can access each object:

[AjaxMethod] public string GetAnyJavaScriptObject(IJavaScriptObject o) { if(o is JavaScriptArray) return "array"; else if(o is JavaScriptBoolean) return "boolean"; else if(o is JavaScriptNumber) return "number"; else if(o is JavaScriptString) return "string"; else if(o is JavaScriptObject) return "object";

return null; }