473,748 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET 2.0 - Dynamically create ActiveX object using HtmlGenericCont rol and call methods / functions all from code behind

HELP :-)... I'm creating an embedded activex object in an asp.net page
using the HtmlGenericCont rol class. I'm doing this because when I
tried to embed it directly in the aspx page, it stopped working once I
changed it to run on the server (runat="server" ). It said the GUID was
wrong. I found code showing how to implement an activex control using
the HtmlGenericCont rol class from the code behind file, but I can't
figure out how to call functions or methods on it. Any help would be
greatly appreciated.

Nov 19 '05 #1
4 3440
Is the ActiveX object you are calling actually a control? If it is, you
need to use the client-side object scripting model to call it's
functions and methods from within the browser. I don't have much
experience with that, because I try to stay away from client-side
scripting (its yucky to write and debug).

If it is just an ActiveX COM object, then to use it on the server side,
you create a Project Reference to that component in your web project,
and then you can instantiate it in your server-side code like this:

Dim myObject as New CustomActiveXCo mponent
myObject.DoSome thing()

If it is referenced correctly, it should show up in Intellisense when
you declare the object, and when you hit the period, you should see the
methods and properties of the class.

Mike

qu*********@hot mail.com wrote:
HELP :-)... I'm creating an embedded activex object in an asp.net page
using the HtmlGenericCont rol class. I'm doing this because when I
tried to embed it directly in the aspx page, it stopped working once I
changed it to run on the server (runat="server" ). It said the GUID was
wrong. I found code showing how to implement an activex control using
the HtmlGenericCont rol class from the code behind file, but I can't
figure out how to call functions or methods on it. Any help would be
greatly appreciated.


Nov 19 '05 #2
Thanks for the reply...

I'm trying to use client-side scripting now, but can't seem to get my
function to recognize the dynamically created object. The script error
I keep getting is "object required". It is however an ActiveX COM
object, but when I create an instance of it, I can't figure out how to
then place it into the webpage. It works fine with windows forms
because when I add a reference to it, it automatically creates the
wrapper and places it into the tool box. In asp, it creates the
wrapper, but won't add it to the tool box for a nice and easy drag and
drop. Thanks again Mike for the reply.

Mike.

Nov 19 '05 #3
if use put a runat=server on an <object> tag, asp.net assumes you are
creating a server side active/x control by guid, not rendering an client
side object tag. it simular to putting a runat=server on <script>. so your
approach is correct.

to access the control from client side (assumming the control is marked safe
for scripting and the browser's security level allows active/x controls),
you need an id tag on the object. because you are using a serverside
control, it generates the id. (view source to see it).

now in browser active/x controls are loaded async, and have a readyState
property that the client script checks to see if its ready. at page load
time, the object should be defined (but may not be ready). so try:

var obj = document.getEle mentById('name' );
if (obj && obj.readyState == 4)
{
// can talk to the object
}
-- bruce (sqlwork.com)


<qu*********@ho tmail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
HELP :-)... I'm creating an embedded activex object in an asp.net page
using the HtmlGenericCont rol class. I'm doing this because when I
tried to embed it directly in the aspx page, it stopped working once I
changed it to run on the server (runat="server" ). It said the GUID was
wrong. I found code showing how to implement an activex control using
the HtmlGenericCont rol class from the code behind file, but I can't
figure out how to call functions or methods on it. Any help would be
greatly appreciated.

Nov 19 '05 #4
I finally got the client side script to work. What is strange is how
all of my controls are set to runat="server". I have a button, a text
box, and an activex component all running with the runat="server" tag,
but when I run them remotely, the app behaves as if they are all
running on the local client. It is strange that if I take this code
and just define everything in the aspx page instead of going about from
code behind, I get the guid error. If I take the wrapped activex
control and define it in code behind, I can't seem to figure out how to
add it to the webpage. In a windows form, I just drag and drop the
object onto the form.

{
HtmlInputText rdpText = new HtmlInputText() ;
rdpText.Attribu tes.Add("type", "text");
rdpText.Attribu tes.Add("id", "text1");
//rdpText.Attribu tes.Add("value" , "text");
rdpText.Attribu tes["runat"] = "server";
Page.Controls.A dd(rdpText);

HtmlInputButton rdpButton = new HtmlInputButton ();
rdpButton.Attri butes.Add("type ", "button");
rdpButton.Attri butes.Add("id", "button1");
rdpButton.Attri butes.Add("name ", "button1");
rdpButton.Attri butes.Add("valu e", "Connect");
rdpButton.Attri butes["runat"] = "server";
rdpButton.Attri butes.Add("oncl ick", "return
Button1_onclick ()");
Page.Controls.A dd(rdpButton);

HtmlGenericCont rol rdp = new HtmlGenericCont rol("object");
rdp.Attributes["id"] = "rdp";
rdp.Attributes["name"] = "rdp";
rdp.Attributes. Add("classid",
"clsid:7584 c670-2274-4efb-b00b-d6aaba6d3850");
rdp.Attributes["runat"] = "server";
rdp.Attributes["width"] = "1034";
rdp.Attributes["height"] = "778";
Page.Controls.A dd(rdp);

HtmlGenericCont rol rdpFunctions = new
HtmlGenericCont rol("script");
rdpFunctions.At tributes.Add("t ype", "text/javascript");
rdpFunctions.At tributes.Add("l anguage", "javascript ");
rdpFunctions.At tributes["runat"] = "server";

string rdpConnect = "function Button1_onclick ()" +
"{" +
"rdp.Width=1034 ;" +
"rdp.Height=778 ;" +
"rdp.DesktopWid th=1024;" +
"rdp.DesktopHei ght=768;" +
"rdp.Server=tex t1.value;" +
"rdp.Connect(); " +
"}";

string rdpDisconnect = " function disconnect()" +
"{" +
"rdp.Disconnect ();" +
"}";

rdpFunctions.In nerHtml = rdpConnect;
rdpFunctions.In nerHtml = rdpFunctions.In nerHtml +
rdpDisconnect;
Page.Controls.A dd(rdpFunctions );

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2807
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of function descriptors for the overloaded functions of that name. A function descriptor would contain the address of the function to be called, and a description of the parameters that it must take. b. A list of parameters. This would be compared to the...
8
4833
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
11
2295
by: Steven D'Aprano | last post by:
Suppose I create a class with some methods: py> class C: .... def spam(self, x): .... print "spam " * x .... def ham(self, x): .... print "ham * %s" % x .... py> C().spam(3) spam spam spam
1
8648
by: Craig | last post by:
I am having problems getting an ActiveX DLL written in VB6 to call a method in a C# class library component. My C# DLL is called CSharpProject.dll and contains a public class called CSharpClass. In this class is a single public method that returns the string "Hello from C sharp". My VB6 ActiveX DLL references the C# DLL (CSharpProject.dll) using the
0
2129
by: theo | last post by:
Hello..I have a similar issue as yesterday but the situation has slightly changed so perhaps someone can shed some more light on the issue... Program flow - load file,extract xml text tags from file,then depending on the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the placeholder,the user selects the required tags from the dropdownlists (if 5 Xml tags,then 5 dropdownlists...
4
2398
by: Sachin_M | last post by:
Hi Friends, I've developed an activeX control (.ocx) using VB 6.0 it has two Public functions, which chages some values of text boxes of the control. Fun1(int a) Fun2() How to use this control in ASP.NET (C#)? I've added reference to my web application.
3
5731
by: Quentin | last post by:
Hey there ! I made my own WebControl, that inherits from WebControls, and i added an HtmlTable to it. I would like to include a file, dynamically, to one of its cells... I've already searched, and found HttpContext.Current.Server.Execute("mapage.aspx") but it executes the page where i call it, and not in the cell... i also tried something like that : MyTable.Rows(0).Cell(0).InnerHtml = Server.Execute("MaPage.aspx") but it doesn't...
1
1022
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a variable (targetId) in to the usercontrol (IntergySite.aspx) by calling its setter method. Currently, I am using if-then-else and hardcoded the User Control Object to do casting and call the setter method. Question: Is there any way I could load,...
5
9768
by: Angel | last post by:
Is there a way to create an IFRAME dynamically via VB.NET. In other words creating the HTML element in the server side code? thanks in advance....
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.