Click here to Skip to main content
15,887,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using web browser control for one of my application.
I need the javascript function in the document to call a function in the application through objectforscripting.

I have set the object for scripting like this
webBrowser1.ObjectForScripting = this;

and I am using a function like this
C#
public void getData()
       {
lbl.Text="Something";

       }


I am calling the function like this
XML
<script type="text/javascript">
function callFunc(){window.external.getData();}
</script>


I am always getting the error "Unable to get property 'getData' of undefined or null reference".

Do u guys know any solution for this. ??
Posted
Comments
Where you set the ObjectForScrpting?

1 solution

Principally and first of all:

1) you can't test for or invoke a function before the Object is rendered on the page, so you will have to interact With the Control after the page is drawn in the browser (See jquery document.ready() for example)
2) It sounds very, very strange to put a webbrowser Control onto a web page

If it is in a winforms Application, you have the following option:

Link to info



or this to bring you further (since the question was very vague:

More info
 
Share this answer
 
v3
Comments
Prasaad SJ 1-Jun-14 22:41pm    
Hi.. Thanks for the reply. I am using the WebBrowser control on a windows application. I figured out later that I am using "webBrowser1.ObjectForScripting = Form.ActiveForm;" under the document_completed event. "webBrowser1.ObjectForScripting=this" under Form load event gives me the correct solution. Thank you guys.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900