2

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 ???

1 Answer 1

1

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.

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

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.