Hi All,
I have created an ActiveX component, but not able to access that ActiveX compoment in ASP.NET. It gives "Microsoft JScript runtime error: Automation server can't create object" error message while creating activeX object using javascript.
ActiveX Component Code:
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace FirstActiveX
{
[Guid("465F2D2E-C638-413e-A353-01E09DC4C7ED")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IMyActiveX
{
[DispId(1)]
string FirstName{ get; set;}
[DispId(2)]
string LastName { get; set; }
[DispId(3)]
string Address { get; set; }
[DispId(4)]
void Show();
}
[Guid("8975D137-9D96-492c-87AE-37D653BADE16")]
[ProgId("FirstActiveX.MyActiveX")]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IMyActiveX))]
[ComVisible(true)]
public class MyActiveX : IMyActiveX
{
#region IMyActiveX Members
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public void Show()
{
MessageBox.Show(string.Format("Mr. {0} {1}, Address : {2}", FirstName, LastName, Address));
}
#endregion
}
}
HTML Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebActiveXTest._Default" %>
<!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 runat="server">
<title></title>
</head>
<script language="javascript" type="text/javascript">
function UseActiveX() {
var x = new ActiveXObject("FirstActiveX.MyActiveX");
x.FirstName = "Nirajan";
x.LastName = "Singh";
x.Address = "Kamothe, Navi Mumbai";
alert(x.FirstName);
return false;
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnShow" runat="server" Text="Show" OnClientClick="return UseActiveX();" />
</div>
</form>
</body>
</html>
Thanks in advance.
Nirajan Singh