Using an ActiveX ocx control on a Webform

M

Mehr H

I have been working on this for several days and am still have had no
success in achieving this. Pleae help. It seems that documentation for this
is very limited. I have looked in several books and they all seem to say
either nothing about this or that this is "out of the scope of this book",
even "Professional ASP.NET".

I have a ActiveX component that I'd like to expose through a .NET wrapper so
in the case that a client browses to my aspx page and does not choose to
download the ActiveX I can Automate the ActiveX object through the .NET
Wrapper on the Server and then stream the result of the ActiveX object
output to the client as a JPG.

Here is all I've done so far:

I've used the AxImp utility to create a new dll, called AxMyActiveX.dll.
I've also asked for it to give me the source code for this type library and
it has and it is called Interop.AxMyActiveX.cs.
I have added this line of code
[System.ComponentModel.ToolboxItemAttribute(true)]
in order to be able to view the "UI" of this ActiveX control to my .cs file
and then used the command line csc to recompile and build the new
Interop.AxMyActiveX.dll.

I create a new ASP.NET webApplication. I have one ASPX page. I browse to my
Interop.AxMyActiveX.dll and set my reference to this dll.
Since .NET is free threated by default and I am attempting to use a COM
component I have set the following attribute
AspCompat="TRUE" (which forces the page to execute in STA mode) in my ASPX
file ( the file into which I am attempting to add my Interop.AxMyActiveX
object).

I switch into Design mode and go to my toolbox and select Add/Remove Items.
I browse to my Interop.AxMyActiveX.dll. The item "AxMyActiveX" appears in
the toolbox but it is GRAYED OUT!

If I try to create the control programmatically from within my page load
event such as below

private void Page_Load(object sender, System.EventArgs e)
{

AxMyActiveXControl AxMyActiveX= new AxMyActiveXControl.AxMyActiveX();

AxMyActiveX.SetSomeProperty = true;

}

and then set an exposed property which takes a bool value I get an exception
thrown such as :

Server Error in '/AFRWS' Application.
----------------------------------------------------------------------------
----

Exception of type InvalidActiveXStateException was thrown.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Windows.Forms.AxHost+InvalidActiveXStateException:
Exception of type InvalidActiveXStateException was thrown.

Source Error:

Line 62:
Line 63:
Line 64: AxMyActiveX.SetSomeProperty = true;
Line 65:
Line 66:

Source File: c:\pathtomyfile.aspx Line: 64

Stack Trace:

[InvalidActiveXStateException: Exception of type
InvalidActiveXStateException was thrown.]
AxMyActiveXControl.AxMyActiveX.set_SetSomeProperty (Boolean value)
PathtoMyFile.Page_Load(Object sender, EventArgs e) in
c:\Pathtomyfile\MyPage.aspx.cs:64
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()



I have no idea what I'm doing improperly but I can't get this to work. I
tried using the item in the design mode of a regular .NET Windows Control
Library and I was able to add the item into the toolbox and it was available
(not grayed out). I was able to drag it onto the design window and compile
it as a usercontrol. Then I created a windows application and I was able to
drag this new usercontrol onto the form and everything ran and worked just
fine. Please help!
Thanks so much,
Mehrh
 
J

jeff

Did you ever meet your needs as described below?
I would be very anxious to do the same thing.
Do you have any sample project you can share ?

* * Please include a copy of this message with your reply

Jeff Bennett
(e-mail address removed)



=================== ===================

Mehr said:
I have been working on this for several days and am still have had no
success in achieving this. Pleae help. It seems that documentation for this
is very limited. I have looked in several books and they all seem to say
either nothing about this or that this is "out of the scope of this book",
even "Professional ASP.NET".

I have a ActiveX component that I'd like to expose through a .NET wrapper so
in the case that a client browses to my aspx page and does not choose to
download the ActiveX I can Automate the ActiveX object through the ..NET
Wrapper on the Server and then stream the result of the ActiveX object
output to the client as a JPG.

Here is all I've done so far:

I've used the AxImp utility to create a new dll, called AxMyActiveX.dll.
I've also asked for it to give me the source code for this type library and
it has and it is called Interop.AxMyActiveX.cs.
I have added this line of code
[System.ComponentModel.ToolboxItemAttribute(true)]
in order to be able to view the "UI" of this ActiveX control to my ..cs file
and then used the command line csc to recompile and build the new
Interop.AxMyActiveX.dll.

I create a new ASP.NET webApplication. I have one ASPX page. I browse to my
Interop.AxMyActiveX.dll and set my reference to this dll.
Since .NET is free threated by default and I am attempting to use a COM
component I have set the following attribute
AspCompat="TRUE" (which forces the page to execute in STA mode) in my ASPX
file ( the file into which I am attempting to add my Interop.AxMyActiveX
object).

I switch into Design mode and go to my toolbox and select Add/Remove Items.
I browse to my Interop.AxMyActiveX.dll. The item "AxMyActiveX" appears in
the toolbox but it is GRAYED OUT!

If I try to create the control programmatically from within my page load
event such as below

private void Page_Load(object sender, System.EventArgs e)
{

AxMyActiveXControl AxMyActiveX= new AxMyActiveXControl.AxMyActiveX();

AxMyActiveX.SetSomeProperty = true;

}

and then set an exposed property which takes a bool value I get an exception
thrown such as :

Server Error in '/AFRWS' Application.
----------------------------------------------------------------------------
----

Exception of type InvalidActiveXStateException was thrown.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Windows.Forms.AxHost+InvalidActiveXStateException:
Exception of type InvalidActiveXStateException was thrown.

Source Error:

Line 62:
Line 63:
Line 64: AxMyActiveX.SetSomeProperty = true;
Line 65:
Line 66:

Source File: c:\pathtomyfile.aspx Line: 64

Stack Trace:

[InvalidActiveXStateException: Exception of type
InvalidActiveXStateException was thrown.]
AxMyActiveXControl.AxMyActiveX.set_SetSomeProperty (Boolean value)
PathtoMyFile.Page_Load(Object sender, EventArgs e) in
c:\Pathtomyfile\MyPage.aspx.cs:64
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()



I have no idea what I'm doing improperly but I can't get this to work. I
tried using the item in the design mode of a regular .NET Windows Control
Library and I was able to add the item into the toolbox and it was available
(not grayed out). I was able to drag it onto the design window and compile
it as a usercontrol. Then I created a windows application and I was able to
drag this new usercontrol onto the form and everything ran and worked just
fine. Please help!
Thanks so much,
Mehrh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top