views:

258

answers:

5

i want to use AJAX and javascript in window platform ...can i use it in vs 05 C# window?

+4  A: 

The options I know about:

  1. JSC.exe
    You can compile Javascript into a managed assembly, and call it as you would any .NET assembly.
  2. COM
    You can package Javascript logic as COM, and call it from .NET, or from any COM environment. Example.

EDIT: This allows Javascript, but not AJAX. AJAX is a term that specifically applies to browsers, primarily using Javascript to retrieve information and potentially dynamically update the browser page without an explicit page refresh. This generally doesn't make sense in a Windows Form app built in C#, because you have C#, and asynchrony is built in to the .NET platform.

Cheeso
plz give me a example code or any efficient tutorial link ....
Shamim
Either one of those is a lot of work and probably more code than can be posted here. At least the COM method is.
jeffamaphone
The COM method is not too complicated; there's a link showing how to package Javascript as COM, that link has full working source code and employs the Google Diff/Match/Patch Javascript library as an the basis for the example. It's bona fide.
Cheeso
JSC is a compiler for going the other way - C# compiled into Javascript
mcintyre321
I don't think so. I think JSC.exe compiles Javascript into IL, just as vbc.exe compiles VB.NET into IL. Just as I said above.
Cheeso
A: 

You cannot use JavaScript/JScript to write code as part of a Windows Forms Application. It seems you are after asynchronous data transfer functionality (posh ;) / AJAX which will need to be implemented seperately. Alternatively, if you are looking to provide a scripting language to your users, try IronPython

For a more detailed answer, state in the question the specific part of JavaScript you would like to use, and we'll give alternatives.

EDIT: Oh. You can! Look at the answer above.

Lucas Jones
+1  A: 

Erm - AJAX is just the name for the techonologies and patterns used to make HTTP requests in Javascript. Javascript itself will run in any Javascript engine; most browsers embed one, and you can also use the Rhino standalone engine (though a lot of Javascript will assume a browser environment, which can get flaky).

C# is not Javascript, and to my knowledge, Visual Studio is not a Javascript interpreter. Why are you trying to do this?

Andrzej Doyle
i want to show a text box in my form .....if user write any thing it show .....how many character you have write ...like stackoverflow add comment ....how can i do it? i may use it in validation check ......
Shamim
Forget Ajax - you don't need to make an HTTP request to count characters (Stackoverflow doesn't). I suggest asking the actual question rather then an X-Y question ( http://www.perlmonks.org/index.pl?node_id=542341 ) - especially when Y won't even come close to solving X.
David Dorward
+1  A: 

You can just add a System.Windows.Forms.WebBrowser to your app, navigate it to whatever HTML + JS page you want, and do all the AJAX you want there.

jeffamaphone
I mean, lets not make this more complex than it needs to be.
jeffamaphone
A: 

You can use Rhino javascript engine, running on IKVM

mcintyre321