C # interaction between ActiveX and JS: only describes how JavaScript calls ActiveX.

Source: Internet
Author: User

For more information about how to write ActiveX programs, see my Blog C # compile ActiveX Control http://blog.csdn.net/hndkbadxv/article/details/9084167

Step 1: Add a method and an attribute to the control class

Public String shownow ()
{
Return datetime. Now. tostring ();
}

Private string _ STR;
Public String Str
{// Get and set must be completely written, not just get or set
Get {return _ STR ;}
Set {_ STR = value ;}
}

Step 2: write code in HTML

Object ID = "activexdemo" name = "activexdemo" classid = "CLSID: 0a031ca1-6b7c-409d-8fc8-ffe4e0fcee94" {guid of the control Class header} width = "400px"
Height = "38" viewastext>
<Param name = "str" value = "pass control attributes with Param"/> // send a value to the STR attribute
</Object>
<Input type = "button" onclick = "alter (activexdemo. shownow ();" value = "test"> </input> // call a method

If the following prompt appears in the lower left corner of the webpage:The object does not support this attribute or method.

Solution: 1. Check whether the control Class header has only the guid attribute. If there are other attributes, delete them. For example, [GUID ("0a031ca1-6b7c-409d-8fc8-ffe4e0fcee94"), classinterface (classinterfacetype. none), comvisible (true)], delete the yellow part; repackage and deploy

2. If the same error is returned after 1 is executed, check whether the guid in the control Class header is the same as the guid in the project -- Right-click -- Property -- Application -- assembly information. If the guid is the same, change the guid to another value.


If you have any questions, leave a message for consultation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.