0

Possible Duplicate:
Embedding JavaScript engine into .NET (C#)

I have a script like this:

var myObject=new Object();
myObject="Hello";

If I refer the script in browser, I can make use of myObject just like below:

<script src="myObject.js" type="text/javascript">
<script type="text/javascript">
    alert(myObject);
</script>

Can I execute the script in C# without browser? It should be like below:

//These are C# Code
string result = ????????
Community
  • 1
  • 1
Domi.Z
  • 11
  • 1
  • 1
  • 1

3 Answers3

0

not getting your question properly i think you are using the term browser in place of html if it' so then there is a method Page.RegisterClientScriptBlock();

for more detail read on http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx

you can use this in whicever event you want to run the script .

not that i assumed browse==HTML code

Devjosh
  • 6,450
  • 4
  • 39
  • 61
0

Have you checked Page.ClientScript.RegisterStartupScript() method http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx

the page have an examples

Ahmed Magdy
  • 5,956
  • 8
  • 43
  • 75
0

Well,

i think you're a bit confused. try first to understand the difference between Client side-script and Server-side code.

Basically server-side produces the rendered html for client-side(your browser).

It is not possible to create objects like your example, you have to use JSON to get objects from server.

but if you what to get the object value on c#, you must send it to the server, on a and parse it on your server side

Flavio CF Oliveira
  • 5,235
  • 13
  • 40
  • 63
  • It's a good answer but looking at the question closer, it's not implied that he's even writing a web application. I think what he wants is to use Javascript as a scripting language for his C# application server side.. – MattDavey May 09 '11 at 09:26
  • On this case it seems to be a mistake, is it possible to use javascript as server-site language?, usually the languages are vb.net e c#, i dont know if is possible to use javascript to do that!! – Flavio CF Oliveira May 09 '11 at 09:39
  • Yes it's possible, server side javascript is becoming a very popular alternative to things like LUA or Python. It's quite popular for writing plugins for example - I think many Adobe products (Photoshop etc) use Javascript as a scripting language – MattDavey May 09 '11 at 10:10