[IronPython] Get a string from JavaScript to IronPython

Kristian kristian.jaksch at gmail.com
Tue Jan 6 15:08:15 CET 2009

I have a code editor written in JavaScript on my page and I want to
send the code that it is typed in as a string to IronPython so that it
can be executed from IronPython. I got this to work in C# but not in
IronPython. Below is the JavaScript I use:

    <script type="text/javascript">

                 var textarea = document.getElementById('code');
                 var editor = new CodeMirror(CodeMirror.replace
(textarea), {
                 height: "350px",
                     width: "500px",
                     content: textarea.value,
                     parserfile: ["tokenizejavascript.js",
                     stylesheet: "css/jscolors.css",
                     path: "js/",
                     autoMatchParens: true

                 function invokeManagedCode() {
                     var form = document.getElementById("editor");
                     var user = form.user.value;
                     var control = document.getElementById("sl2");

The code replaces a standard HTML-textarea with the JavaScript editor.
The function "invokeManagedCode()" sends the text in the code editor
to a C# method. The C# code is really simple:

namespace htmlDom1
    public partial class Page : UserControl
        public Page()
            HtmlPage.RegisterScriptableObject("codeProvider", this);

        public void Code(string codeString)
            this.Message.Text = codeString;


How can I achieve the same in IronPython? I tried to do exactly the
same as in C#. See below:

def Code(codeString):
    root.sl2TextBox.Text = codeString # Show that it works by writing
the string
                                                       # from the
javascript code editor to a Silverlight textbox

HtmlPage.RegisterScriptableObject("codeProvider", Code)

But this doesn't work. How to do it properly?

Thanks for help!

More information about the Ironpython-users mailing list