views:

205

answers:

1

Hello!
I try to make scriptable application using Silverlight DLR. When I try execute JScript code which contains two or more lines of code, execution only first line. For example: I had Compiled SL application written on С#. Main page contains Label named "lblMessage" and Button with Click event handler.

private void Button_Click(object sender, RoutedEventArgs e)  
{  
  ScriptRuntime scriptRuntime = ScriptRuntime.Create();  
  foreach (string name in new string[] { "mscorlib", "System", "System.Windows", "System.Windows.Browser", "System.Net" })
  {
     scriptRuntime.LoadAssembly( scriptRuntime.Host.PlatformAdaptationLayer.LoadAssembly(name) );  
  }  
  ScriptEngine scriptEngine = scriptRuntime.GetEngine("js");  
  ScriptScope baseScope = scriptEngine.CreateScope();  
  gsFormManager fm = gsApplicationManager.FormManager;  
  baseScope.SetVariable("lblMessage", lblMessage);  
  string script = "lblMessage.Text = 'First line of code';\r\n" + "lblMessage.Text = 'Second line of code'";  
  ScriptSource scriptSource = scriptEngine.CreateScriptSourceFromString(script);  
  CompiledCode compiledCode = scriptSource.Compile();  
  compiledCode.Execute(baseScope);  
}

After execution Label.Text will be equal "First line of code" string.

Why ignored second line of code ?

Thank you.

A: 

Maybe you should also put a ';' at the end of second line...?

erdogany
I tried to do this, and has samr result. Second Line ignored.string script = "lblMessage.Content = 'First line of code';\r\n" + "lblMessage.Content = 'Second line of code;\r\n'";