[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1618
  • Last Modified:

How to create a object at run time?

I searched the web and found some answer.  however most were unclear.

I need to create an object (activex control) on the fly based up what type of monitor the users has choosen. User choice is stored in a database.  Pseudo coded would look soemthing like this

If (MonitorType == "SERIAL")
{
 createobject  name="m1Control" CLASSID="1345677854253124321s"
                        codebase="m1control.CAB#version=1,0,0,17" height="20" width="120"
                        viewastext id="m1Control">
}
else
{
 createobject  name="M2Control" CLASSID=890749587495812749057194"
                        height="20" width="120" viewastext id="M2Control">
}

The first activex is seldom change (but we must support) is written in VB.  Second activex control is new and written in VC++.

Question is what are the command(s) to do this on the page load event?  is this possible?
0
DLueck
Asked:
DLueck
1 Solution
 
Bob LearnedCommented:
Hmmm...

It might be possible to define both the ActiveX controls in the HTML, and then toggle the visibility.  

I am curious what these ActiveX controls do?

Bob
0
 
RejojohnyCommented:
you can dynamically render scripts to the generated page using page.clientscript.registerclientscriptblock .. you can do this on page load .. check the condition and render the code to create the activex control required ..

>>Second activex control is new and written in VC++.
do note that only COM activex controls will work on a web page and that too by default on IE (depending on the security settings) .. for other browsers, the user might need some plugins ..

Rejo
0
 
DLueckAuthor Commented:
I solved my answer.....

I had to change add a literal control on the web page :
<asp:Literal ID="VitalsLiteral" runat="server"></asp:Literal>

Than in the page load, i added the following code..
...
        get monitor information and setting from database
...
        if (MonitorType.ToUpper() == "PORT")
        {
            // load object onto page
            strObject = "<object name='VitalsControl' ";
            strObject += "CLASSID='CLSID:A176D37E-5B0C-4443-90BA-EAAA4F885B41' ";
            strObject += "codebase='vitals\\cab\\cMoreVitalsNet.CAB#version=1,0,0,17' ";
            strObject += "height='20' ";
            strObject += "width='120' ";
            strObject += "viewastext id='VitalsControlNet'>";
            strObject += "</OBJECT>";
        }
        else
        {
            // initialzie parameter variables
            string LogIntervalTime = string.Empty;
            string LogEvents = string.Empty;
            string StartUpDelay = string.Empty;

            // get the monitor settings from the database
            foreach (VMGetVMTypeAndSettings VMTS in VM_GetVMTypeAndSettings)
            {
                switch (VMTS.SettingID.ToUpper())
                {
                    case "NINTERVAL":
                        LogIntervalTime = VMTS.DataValue;
                        break;
                    case "DEBUG_MODE":
                        LogEvents = VMTS.DataValue;
                        break;
                    case "STARTUP_DELAY":
                        StartUpDelay = VMTS.DataValue;
                        break;
                }
            }

            // load object onto page
            strObject = "<OBJECT ID='CGUSBVitals1' ";
            strObject += "WIDTH=120 ";
            strObject += "HEIGHT=20 ";
            strObject += "CLASSID='CLSID:DD698DA9-9D32-4F12-8D7C-789E129BB367' ";
            strObject += "codebase='vitals\\cab\\MCGUSBCab.CAB#version=1,0,0,1'> ";
            strObject += "<PARAM NAME='_Version' VALUE='65536'>";
            strObject += "<PARAM NAME='_ExtentX' VALUE='2455'>";
            strObject += "<PARAM NAME='_ExtentY' VALUE='709'>";
            strObject += "<PARAM NAME='_StockProps' VALUE='0'>";
            strObject += "<PARAM NAME='MonitorName' VALUE='" + MonitorName + "'>";
            strObject += "<PARAM NAME='LogIntervalTime' VALUE='" + LogIntervalTime + "'>";
            strObject += "<PARAM NAME='LogEvents' VALUE='" + LogEvents + "'>";
            strObject += "<PARAM NAME='StartUpDelay' VALUE='" + StartUpDelay + "'>";
            strObject += "<PARAM NAME='Caption' VALUE='" + MonitorName + "'>";
            strObject += "</OBJECT>";
        }
        this.VitalsLiteral.Text = strObject;
    }

==end code===

The correct object (activex) comes up each time I select a different type of monitor (serial vs usb)

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
DLueckAuthor Commented:
Bob,

The activexes request/get data from a patient vitals monitor (blood pressure, heart rate, O2 percentage).

Alot of the monitors are connect to the serial port.  However the new ones coming out are starting to be connect by tghe usb port.  

So we decide to leave the old one alone (serial port) and make a new one for all the usb type monitors.

In the database I store the monitor type (comm/usb).  Based upon the monitor type, that activex control needed to be loaded onto the web page.

hope that answers your question.
0
 
RejojohnyCommented:
i thought that the sugestion i made was similar to the final approach taken .. the difference been using a literal control instead of using registerclientscriptblock ..
0
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now