Reputation: 51
I have active-x class written in c# which is multi-threaded. I need to call javascript from my activeX. I tried it by Microsoft.mshtml .
/*JS
function do_Print() {
control.setPage(this);
control.scriptPrint();
}
function report_back(report){
alert("Report:"+report);
}
C#
public void setPage(mshtml.HTMLWindow2Class JSFile) {
window = JSFile;
}
public void scriptPrint(){
window.execScript("report_back('Printing complete!')", "JScript");
}
*/
But its throwing exception
"unable to cast COM object of type 'mshtml.HTMLWindow2Class' to interface type 'mshtml.DispHTMLWindow2'"
Is there another way round. I am able to call active-x function from java script but vice versa still got above exception. Any idea for multi-threaded c# active-x calling javascript function ???
Upvotes: 2
Views: 2610
Reputation:
you can access html like this
private void MyControl_Load(object sender, EventArgs e)
{
if (this.Site != null)
{
htmldoc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));
}
}
then on any button click on our C# control invoke method to click html button
HtmlElement setCLIButton = htmldoc.GetElementById("searchButton");
setCLIButton.InvokeMember("onClick");
by this way you can call your javacsript function hope it will help someone.
Upvotes: 1