Page view counter

How do I Write that In JavaScript?

A comment was left in response to Master Detail in Silverlight 2 asking "Any hint how to create such a sample with Java Script instead C#?"

I thought the answer was important enough to post to the blog in general...

MultiLanguageTwo points about your question. The first is whether you are asking if one can write this same program in JavaScript in Silverlight 2 (answer: yes) or you are asking if one can write the same program in Silverlight 1.0 (which only uses Javascript) (answer: depends).

Second point is that there are a number of languages that SL2 supports: IronRuby, JavaScript, VB, C#, etc., and (frankly) it won't be possible for me to illustrate all of them (or even most of them) in these examples, but it shouldn't be terribly hard to translate the logic from one language to another because the code is pretty simple and the Silverlight documentation shows the syntax for each event, method and property in the various languages.

While it is true that Silverlight 2 supports JavaScript, it is also true that C# supports language features that simply are not available in Javascript such as generics (ListOf<Books>) and true classes and objects. Translating my examples from C# to (e.g.,) VB is trivial, but translating to JavaScript is more of a challenge.

Which brings me to my final point, which is that I honestly can't imagine why you'd want to do this in Javascript; the code will be slower, harder to maintain and harder to create.

If you'll pardon what may sound rude and even arrogant, I think you'll be a lot happier if you take the opportunity to "step up" to managed code (see, for example, Programming C# 3.0, 5th Edition by my favorite author) which will not only enhance your Silverlight experience, but will bring you nicely into the entire spectrum of .NET programming from ASP.NET, ASP.NET/AJAX through WPF, WCF, Workflow, etc.

Programming C# 3.0 (Programming)
by Jesse Liberty, Donald Xie

Read more about this title...

You'll love it. I tried it in 2000 and never looked back.

 

 

 

 

 

 

 

Published 17 March 2008 11:05 AM by jesseliberty

Comments

# Thomas H. said on 17 March, 2008 12:13 PM

Hi Jesse,

thank you for your fast response! :-) But this is not that I´m looking for. I´m looking for a kind of “loose XAML” where the browser Java Script is used for code behind. I want to use the Silverlight XAML with the new Silverlight 2 Controls as a kind of “new HTML” in Ajax style.

Like described here

www.kudzuworld.com/.../20061231.no.aspx

Why I´m asking for using Java Script? Why not using C# or any other DLR language? Because I have a huge server app written in Smalltalk with hundreds of model classes with business logic. This server app generates now HTML and Java Script and is used via browsers.  This app has about 300 views and is used by ten thousands of users. I´m considering using Silverlight as the new frontend in the browser instead the plain HTML. The goal is to offer rich controls and more desktop like user experience. For us it would be easy to generate the Silverlight XAML and Java Script from Smalltalk. But we can´t and won´t rewrite the whole app in C#.

So can you please show me an example, how to use the Silverlight 2 controls with browser Java Script?

Greetings Thomas

P.S. Looks like other people are starving for an answer for this question as well:

silverlight.net/.../11573.aspx

# wisecarver said on 17 March, 2008 12:39 PM

Interesting Thomas...

Chad and I used to cross-code Borland Delphi,

I had no idea he was doing XAML now. ;-)

# Community Blogs said on 17 March, 2008 05:17 PM

Brad Abrams posted links the the SL2 poster, Shawn Wildermuth has links out to a discussion of a Cross

# dave_dyson said on 18 March, 2008 04:44 AM

hello Jesse

re article above (snippet below)

While it is true that Silverlight 2 supports JavaScript, it is also true that C# supports language features that simply are not available in Javascript such as generics (ListOf<Books>) and true classes and objects. Translating my examples from C# to (e.g.,) VB is trivial, but translating to JavaScript is more of a challenge.

****

This is exactly would I need - to pass data

to a datagrid using JScript. Maybe a challenge

but can you please help with an code example of how to set up/create the data from JScript.

I guess when you say Javascript you mean managed JScript and not 'native' Javascript.

# dave_dyson said on 18 March, 2008 04:52 AM

Hi Jesse

Just to clarify my last post, when I stated

"I guess when you say Javascript you mean   managed JScript and not 'native' Javascript"

I meant managed JScript supports Silverlight 2

controls while 'native' Javascipt only supports

Silverlight 1.0 controls.

# re: How do I Write that In JavaScript? | My Geek Solutions said on 18 March, 2008 06:55 AM

Pingback from  re: How do I Write that In JavaScript? | My Geek Solutions

# re: How do I Write that In JavaScript? | My Geek Solutions | My Geek Solutions said on 18 March, 2008 09:51 AM

Pingback from  re: How do I Write that In JavaScript? | My Geek Solutions | My Geek Solutions

# Dew Drop - March 18, 2008 | Alvin Ashcraft's Morning Dew said on 18 March, 2008 10:00 AM

Pingback from  Dew Drop - March 18, 2008 | Alvin Ashcraft's Morning Dew

# jesseliberty said on 18 March, 2008 10:53 AM

Thomas,

The thread you pointed me to  indicates that you cannot access the SL2 controls from Javascript (I'll try to get confirmation of that). Further, it is clear to me that the folks in that thread know more than I do about JScript and how one would do what you and Dave Dyson want to accomplish, so I'd pound on that thread looking for answers.

In the meantime I'll continue to look into it.

Thanks!

-j

# re: How do I Write that In JavaScript? | My Geek Solutions | My … | My Geek Solutions said on 18 March, 2008 11:24 AM

Pingback from  re: How do I Write that In JavaScript? | My Geek Solutions | My &#8230; | My Geek Solutions

# Thomas H. said on 18 March, 2008 12:55 PM

Hi Jesse,

thank you for investigating this issue. That´s sad, that the new controls cannot be used from native browser Java Script.

For me this seems to be a political decision from the Silverlight management rather than a technical decision. The same issue is with Flash/Flex: Although Adobe has the Flex Bridge

labs.adobe.com/.../Flex_Framework:FABridge

to create Flash controls at runtime in the AJAX way. But the Flex Bridge is halfhearted and not well supported.

It seems that both, Microsoft and Adobe, want to sell their development environments in order to use Flash/Silverlight generated content. Therefore the AJAX access is blocked.

IMHO if Microsoft will open the controls to native Java Script, Silverlight will become the Flash Killer. All the AJAX developer will adopt it…

Greetings Thomas

# wisecarver said on 19 March, 2008 01:40 PM

Present and Future of BLOCKED SCRIPT

channel9.msdn.com/ShowPost.aspx