Handling ActiveX in ASP.net

P

PhilTheGap

Hi there,

I would like to create an ActiveX object inside my aspx Asp.Net 2.0 page.
Then I would like to have a handler in my code-behind code, in order to
change and access the properties of this ActiveX.

So my first question is: how to create the ActiveX object ? Can I use the
Visual Studio Toolbox to add the COM ocx into a tab and drag and drop it
onto my aspx page ? Can I just write something like <object id="chart1"
classid="clsid:3A2B370C-BA0A-11D1-B137-0000F8753F5D"> in the aspx code ? Do
I need to write a "new object" in the aspx.cs code ?

Then how can I have an ActiveX handle in the .Net code ? I suppose that
access this object with javascript should be much easier, however I have to
set its absolute positions (left and top) with arguments stored in a
database. So how can I get these values from javascript ??

Philippe
 
B

bruce barker

yes and no.

if all your users have the active/x control installed thats all you need. if
they don't then you need to host a install cab and supply a codebase.

in asp.net if you add a runat=server to an object tag, then it becomes a
server side com object, not client. if you need to set parameters use a
generic and set its inner html in the code behind.

also if the control allows user input and you don't want the click to
activate message, then you need to render the object tag block with inline
javascript.

also if the control is not signed as safe for scripting, your users will
need to change their security settings to use the control.

to pass values from codebehind to the rendered javascript just render a
script block setting a variables.

-- bruce (sqlwork.com)
 
J

Jialiang Ge [MSFT]

Hello Philippe,

In addition to bruce's points, I'd suggest the KB article
http://support.microsoft.com/kb/317392. It demonstrates how to host an
ActiveX control in ASP.NET (for your first question), and points out that
ActiveX control is a pure client-side control, the server-side code cannot
access this control (for your second question). Server-side code can access
only server controls, which are the controls that are listed on the Web
Form tab in the toolbox. But do we have any workarounds to get/set ActiveX
control properties from the server-side code? Yes, we have.

A. To set an ActiveX control property from the serve side:
As bruce mentioned, we can render a script block to set the variables. For
example:
Response.Write("<script>myControl1.myProperty='aaa';</script>");
where "myControl1" is the client-side ID of the ActiveX control.

B. To get an ActiveX control property from the server side:
Suppose that you want to get the ActiveX control's property in a asp.net
button Click postback, we can register a client-side onclick event for the
button:
<asp:Button runat=server ID='btn' OnClientClick='clientSideClickEvent'
OnClick='serverSideClickEvent'¡­ />
In the clientSideClickEvent javascript function, we get the ActiveX
control's property and place the value in a hidden field (e.g.
asp:HiddenField). After then, we can get the property value from the
asp:HiddenField control in our server side OnClick call back.

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

PhilTheGap

Hi Jianlang,
Jialiang Ge said:
Hello Philippe,

In addition to bruce's points, I'd suggest the KB article
http://support.microsoft.com/kb/317392. It demonstrates how to host an
ActiveX control in ASP.NET (for your first question), and points out that
ActiveX control is a pure client-side control, the server-side code cannot
access this control (for your second question). Server-side code can
access
only server controls, which are the controls that are listed on the Web
Form tab in the toolbox. But do we have any workarounds to get/set ActiveX
control properties from the server-side code? Yes, we have.

A. To set an ActiveX control property from the serve side:
As bruce mentioned, we can render a script block to set the variables. For
example:
Response.Write("<script>myControl1.myProperty='aaa';</script>");
where "myControl1" is the client-side ID of the ActiveX control.

B. To get an ActiveX control property from the server side:
Suppose that you want to get the ActiveX control's property in a asp.net
button Click postback, we can register a client-side onclick event for the
button:
<asp:Button runat=server ID='btn' OnClientClick='clientSideClickEvent'
OnClick='serverSideClickEvent'¡­ />
In the clientSideClickEvent javascript function, we get the ActiveX
control's property and place the value in a hidden field (e.g.
asp:HiddenField). After then, we can get the property value from the
asp:HiddenField control in our server side OnClick call back.

Please let me know if you have any other concerns, or need anything else.
This post is eally helpful to me.
Thank you very much
 

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

Top