1

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

Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
Shamim
  • 359
  • 4
  • 12
  • 25

5 Answers5

4

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.

Community
  • 1
  • 1
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • Either one of those is a lot of work and probably more code than can be posted here. At least the COM method is. – i_am_jorf May 26 '09 at 15:25
  • 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 May 26 '09 at 15:27
  • JSC is a compiler for going the other way - C# compiled into Javascript – mcintyre321 Aug 11 '09 at 11:39
  • 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 Aug 11 '09 at 17:08
1

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
  • 102,507
  • 33
  • 189
  • 228
  • 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 May 26 '09 at 15:35
  • 1
    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. – Quentin May 26 '09 at 15:39
1

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.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
0

You can use Rhino javascript engine, running on IKVM

mcintyre321
  • 12,996
  • 8
  • 66
  • 103
0

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
  • 19,767
  • 8
  • 75
  • 88