By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,667 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,667 IT Pros & Developers. It's quick & easy.

Microsoft WebBrowser control

P: n/a
I have a Windows Form that uses the Microsoft WebBrowser control. If I load
an HTML file into the control that contains Jscript code, can the Jscript
code call a C# function in my Windows Form?
--
-Bill Cousert
wr*******@yahoo.com

moderator of http://groups.yahoo.com/group/c-sharp-programming
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Bill Cousert" <wr*******@yahoo.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
I have a Windows Form that uses the Microsoft WebBrowser control. If I load an HTML file into the control that contains Jscript code, can the Jscript
code call a C# function in my Windows Form?


Hi Bill,

Try adding your C# object as the "window.external" object. Then JScript
should be able to manipulate it.

Peter

--
Please post questions to the newsgroup - everyone benefits.
This post is provided "AS IS" with no warranties, and confers no rights
Sample code subject to http://www.microsoft.com/info/cpyright.htm
Nov 13 '05 #2

P: n/a

"Peter Torr (MS)" <pt***@microsoft.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
"Bill Cousert" <wr*******@yahoo.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
I have a Windows Form that uses the Microsoft WebBrowser control. If I load
an HTML file into the control that contains Jscript code, can the Jscript code call a C# function in my Windows Form?


Hi Bill,

Try adding your C# object as the "window.external" object. Then JScript
should be able to manipulate it.


Hi Peter,

Would I do this by adding a reference? Assume my function is named test. How
would I call it from JScript?
Thanks,

-Bill Cousert
wr*******@yahoo.com


Peter

--
Please post questions to the newsgroup - everyone benefits.
This post is provided "AS IS" with no warranties, and confers no rights
Sample code subject to http://www.microsoft.com/info/cpyright.htm

Nov 13 '05 #3

P: n/a
"Bill Cousert" <wr*******@yahoo.com> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Hi Peter,

Would I do this by adding a reference? Assume my function is named test. How would I call it from JScript?


Actually, I'm not sure how easy it will be to use the external object in C#
with WinForms. Looking at:

http://msdn.microsoft.com/workshop/b...w/overview.asp

it seems you have to do work in an DocUIHost interface which (presumably)
WinForms implements for you. Maybe you can figure out a way around that.

Anyway, the next best option is to call into IE to get a handle on the
script block, then use Reflection to invoke a member on the script that will
accept a callback object (your C# object) for later use. Kind of messy, but
it should work.

Peter

--
Please post questions to the newsgroup - everyone benefits.
This post is provided "AS IS" with no warranties, and confers no rights
Sample code subject to http://www.microsoft.com/info/cpyright.htm
Nov 13 '05 #4

P: n/a

"Peter Torr (MS)" <pt***@microsoft.com> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
"Bill Cousert" <wr*******@yahoo.com> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Hi Peter,

Would I do this by adding a reference? Assume my function is named test. How
would I call it from JScript?


Actually, I'm not sure how easy it will be to use the external object in

C# with WinForms. Looking at:

http://msdn.microsoft.com/workshop/b...w/overview.asp

it seems you have to do work in an DocUIHost interface which (presumably)
WinForms implements for you. Maybe you can figure out a way around that.

Anyway, the next best option is to call into IE to get a handle on the
script block, then use Reflection to invoke a member on the script that will accept a callback object (your C# object) for later use. Kind of messy, but it should work.

Peter

Thank you! I see I have my work cut out for me. I will post the results when
I figure this out.

Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.