2

I have a WebBrowser control on my WinForm, within which I'm showing a dialog box with jQuery that contains a text area and a button labeled "save", the purpose of which is to obtain data from a user.

When the user clicks the save button I wish to retrieve the text in a text area and store it in a variable in my WinForm application.

Is this possible: jQuery function returning a value to a WinForm application?

2 Answers 2

3

Yes it is.

If you plan to use the standard WebBrowser control for WindowsForm see this property: WebBrowser.ObjectForScripting -- There is a very useful example at the bottom showing you exactly how you would execute Javascript that calls back into your application.

Personally, I don't like the supplied WebBrowser control for WinForms or WPF -- They are simply COM Wrappers for internet explorer. I prefer to use Awesomium.NET.

Sign up to request clarification or add additional context in comments.

Comments

2

Do you specifically want to use jQuery to do this or do you just want to do bidirectional communication? Using jQuery or traditional web practices will require a web server running somewhere for the page to query.

If you just want bidirectional communication, set the WebBrowser.ObjectForScripting property. This exposes a .Net object to the JavaScript code on the web page as window.external. The JavaScript code on the page can then call methods and properties on that object to communication with your WinForms application, like storing the text from the text area when the Save button is pressed.

See http://msdn.microsoft.com/en-us/library/a0746166.aspx for more information.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.