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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • qualitynice@hotmail.com

    ASP.NET 2.0 - Dynamically create ActiveX object using HtmlGenericControl 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.

  • xhead

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

    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

    qualitynice@hot mail.com wrote:[color=blue]
    > 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.[/color]

    Comment

    • qualitynice@hotmail.com

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

      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.

      Comment

      • Bruce Barker

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

        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)




        <qualitynice@ho tmail.com> wrote in message
        news:1131048607 .357635.307600@ g44g2000cwa.goo glegroups.com.. .[color=blue]
        > 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.
        >[/color]


        Comment

        • qualitynice@hotmail.com

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

          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 );

          Comment

          Working...