i want to use AJAX and javascript in window platform ...can i use it in vs 05 C# window?
-
hy would you want to do it in a winform? – Itay Moav -Malimovka May 26 '09 at 15:23
-
yup i want to do it in window form – Shamim May 26 '09 at 15:25
-
4But why? There are other ways to do async HTTP request from C#. – Jakob Christensen May 26 '09 at 15:27
-
2Why, why oh why? Winforms allows on demand C# code which allows so much more than Javascript and AJAX. – cjk May 26 '09 at 15:34
-
jflkjdkfjkljsafkjklsf fjksjfdk – Shamim May 26 '09 at 15:51
-
According to a comment from OP this question doesn't even related on what OP wants to do. Maybe you should rewrite it and post what you really want to achieve?? – gbianchi May 26 '09 at 16:10
5 Answers
The options I know about:
- JSC.exe
You can compile Javascript into a managed assembly, and call it as you would any .NET assembly. - 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.
-
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
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?

- 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
-
1Forget 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
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.

- 53,608
- 15
- 131
- 222
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.

- 19,767
- 8
- 75
- 88