1

I have created a very simple user control ActiveX with a simple button that show up a MessageBox.

namespace AxCPW
{
    public partial class Test: UserControl, ITest
    {
        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello World");
        }
    }
}

Next I have created a web page inside my asp.net project and i have embedded my usercontrol in it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
    <object id="myControl" name="myControl" classid="AxCPW.dll#AxCPW.Test" width="100" height="100">
    </object>
</body>
</html>

The problem is i see a broken image instead my UserControl, i have already added my localhost web server Trusted Sites on IE9 but doesn't works.

I know ActiveX is an obsolete solution, but i need to use a third part sdk dll (to communicate with a device by USB) and i think the only available solution is this

abatishchev
  • 98,240
  • 88
  • 296
  • 433
enginnnn
  • 13
  • 4

1 Answers1

0

ActiveX is a COM technology (essentially it's "COM-in-a-webpage"), and does not understand .NET technology.

To use an ActiveX control that has been developed in C#, you need to expose the interface through COM. Also, you will need to register the DLL using RegAsm, rather than gacutil as you need the COM registration information written to the registry, rather than the assembly added to the GAC. Finally, the classid attribute has to be the COM GUID, not the "friendly name".

If you need to deploy the ActiveX control automatically, and for sample HTML using the GUID, please check out my answer to Deploy C# ActiveX in a CAB for Internet Explorer use.

Community
  • 1
  • 1
RB.
  • 36,301
  • 12
  • 91
  • 131
  • Thanks your answer is very useful! Now i'm following this tutorial(http://www.olavaukan.com/2010/08/creating-an-activex-control-in-net-using-c/) now i'm stuck because when i load my web page UAC box show up, but when i click YES my activex doesn't show up... the page is totally blank – enginnnn Sep 07 '12 at 09:34
  • @enginnnn I only had to make it work with Windows XP luckily! I'm afraid I can't help with UAC issues - sorry :( – RB. Sep 07 '12 at 09:37
  • Disabling UAC i can install my activex(i see it in add/remove programs), but page still blank... – enginnnn Sep 07 '12 at 09:41
  • @enginnnn Please see the "Troubleshooting" section in my answer on http://stackoverflow.com/questions/5484326/deploy-c-sharp-activex-in-a-cab-for-internet-explorer-use/5484527#5484527. IE should give you a log file detailing exactly what went wrong. – RB. Sep 07 '12 at 09:48
  • Where is this file? I can't find it. I'm using IE9 and Windows 7 – enginnnn Sep 07 '12 at 10:01
  • Solved, i did not noticed style="display:none" ... Thanks you! – enginnnn Sep 07 '12 at 10:12