Retrieving Data from ActiveX Control found on ASPX Page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    Retrieving Data from ActiveX Control found on ASPX Page

    I can't believe I'm asking this.
    I've looked everywhere for an answer to what seems to be a simple question...

    How do you retrieve data from an ActiveX control found on an ASPX page?

    I've never used ActiveX controls in a web page and normally I never would...but the web application I'm currently developing requires one.

    I've created the control and have added it to my asp page like so:
    [code=asp]
    <object id="myActiveXCt rl" classid="clsid: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ></object>[/code]

    I'm just not sure how to retrieve the ActiveX control on the server.
    (Well really all I need is the data within the ActiveX control)

    Thanks a lot!

    -Frinny
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well I know how to talk to it from the webpage itself, you could use that to pipeline it back to the server:

    I got this from an example just yesterday, if you instanciate the object with the object tags, you can use the public properties as you like.
    (Since my object was created in .net I had to make an "interface" with the public properties available to it)
    [code=html]
    <body>
    <hr>
    <font face=arial size=1>
    <OBJECT id="myControl1 " name="myControl 1" classid="myax.d ll#myax.myContr ol" width="500px" height="500px">
    </OBJECT>
    </font>
    <form name="frm" id="frm">
    <input type="text" name="txt" value="enter text here">
    <input type=button value="Click me" onClick="doScri pt();return false;">
    </form>
    <hr>
    </body>
    <script language="javas cript">
    function doScript()
    {
    myControl1.User Text = frm.txt.value;
    }
    </script>
    [/code]

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by Plater
      Well I know how to talk to it from the webpage itself, you could use that to pipeline it back to the server:

      I got this from an example just yesterday, if you instanciate the object with the object tags, you can use the public properties as you like.
      (Since my object was created in .net I had to make an "interface" with the public properties available to it)
      [code=html]
      <body>
      <hr>
      <font face=arial size=1>
      <OBJECT id="myControl1 " name="myControl 1" classid="myax.d ll#myax.myContr ol" width="500px" height="500px">
      </OBJECT>
      </font>
      <form name="frm" id="frm">
      <input type="text" name="txt" value="enter text here">
      <input type=button value="Click me" onClick="doScri pt();return false;">
      </form>
      <hr>
      </body>
      <script language="javas cript">
      function doScript()
      {
      myControl1.User Text = frm.txt.value;
      }
      </script>
      [/code]
      Ok, I'd seen this but didn't think it was appropriate for my application.
      I think I can adapt it to suit my needs.

      Thanks a lot Plater!

      -Frinny

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by Plater
        Well I know how to talk to it from the webpage itself, you could use that to pipeline it back to the server:

        I got this from an example just yesterday, if you instanciate the object with the object tags, you can use the public properties as you like.
        (Since my object was created in .net I had to make an "interface" with the public properties available to it
        ...
        I didn't want to put a layer of JavaScript in there and so I was resistant to that recommendation before.

        My ActiveX control (developed in VB6) works fine.
        However my .NET version of the control does not work.
        I'm assuming it's because of some sort of security issue that is preventing it from executing on the client's machine.

        So my next question, naturally, is do you know how to establish a trust between the .NET "ActiveX" control and the client's Operating System?

        Thanks again!

        -Frinny

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          I was going to suggest that you can probably import and instanciate the activeX object in your backend code jsut the way you would an asp:label or whatnot. (set runat="server" ?)

          Yeah there's some mondo trust stuff in there. I couldn't figure it out yesterday so I gave up on it. I was just goofin around.
          There are like securityflags that you can request/assert and then your webpage/server needs to be in the "trusted sites" zone on the browser or something.
          Don't forget to flush out your global cache every time you change your .net activex object!

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by Plater
            I was going to suggest that you can probably import and instanciate the activeX object in your backend code jsut the way you would an asp:label or whatnot. (set runat="server" ?)
            I tried that already but apparently the control will not work with the runat="server" attribute set. Seems a bit crazy to me but that's the way it works.


            Originally posted by Plater
            Yeah there's some mondo trust stuff in there. I couldn't figure it out yesterday so I gave up on it. I was just goofin around.
            There are like securityflags that you can request/assert and then your webpage/server needs to be in the "trusted sites" zone on the browser or something.
            I'll give this a try again...I've tried it in the past without any luck.
            I just really don't want to use a true ActiveX because it lacks the security that a .NET control has.

            Originally posted by Plater
            Don't forget to flush out your global cache every time you change your .net activex object!
            Yeah, testing this stuff does seem to really fill up the global cache with junk quickly.

            Thanks again!

            -Frinny

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Right now I'm using a very simple control.
              It has a label that has some text in it and a text box that has some default text in it (which is then reset by the control's Page Load event)

              The whole .NET ActiveX is as follows:
              [code=vbnet]
              Public Interface IDotNetActiveX
              ReadOnly Property MyString() As String
              End Interface


              Public Class MyControl
              Implements IDotNetActiveX

              Private Sub MyControl_Load( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
              Txt_MyTextBox.T ext = "This is some text loaded in the page Load event...."
              End Sub

              Public ReadOnly Property MyString() As String Implements IDotNetActiveX. MyString
              Get
              Return "This is the String"
              End Get
              End Property
              End Class
              [/code]

              It works fine when I debug it on it's own.
              But when I place it into the aspx page...
              As Such:
              [code=asp]
              <object id="testDotNetA ctiveX" name="testDotNe tActiveX" classid="~/Bin/DotNetActiveXCo ntrol.dll#DotNe tActiveXControl .MyControl" height="300px" width="300px"></object>[/code]

              The TextBox in the control but the label and the text that should be displayed in the TextBox is not displayed.

              This gives me the impression that the control is never loaded.

              I tried demanding permissions but all to no avail.
              (Maybe I shouldn't have gotten rid of my permission demanding code....but...I 'm still looking for thoughts on your problem)

              There seems to be no information on how to debug these sorts of controls.....
              Have you had any luck with your .NET control?



              -Frinny

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                ActiveX controls (of the .NET nature) only load when coming from a webserver (IIS).
                Maybe running them the way you have keeps them from loading?

                I always have to "click" my activex controls for them to run.

                my .net activeX to go along with the html code from earlier:
                Code:
                namespace myax
                {
                	public interface AxMyControl
                	{
                		String UserText { set; get; }
                	}
                	public partial class myControl : UserControl, AxMyControl
                	{
                	  private String mStr_UserText="";
                	
                	  public String UserText
                	  {
                			get { return mStr_UserText; }
                			set
                			{
                			    mStr_UserText = value;
                			    //Update the text box control value also.
                			    txtUserText.Text = value;
                			}
                	  } 
                	
                	  public myControl()
                	  {
                			InitializeComponent();	
                	  }	   
                	}//end of class
                }//end of namespace

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  I'm still stuck.
                  I've been clearing the global cache using the gacutil tool (gacutil /cdl).
                  I've added a Sub that simply writes a string in the TextBox and I call that sub in my JavaScript code...

                  But nothing ever happens....I even tried turning off my anti virus...and setting all of the ActiveX settings in my browser to prompt for any activity....


                  Through this I get the impression that the control is loaded...becaus e I'm being prompted to let the control load...but it just doesn't do anything. (Well it appears that way).

                  My .NET ActiveX looks like this now:
                  [code=vbnet]

                  Public Interface IDotNetActiveX
                  ReadOnly Property MyString() As String
                  Sub LoadMe()
                  End Interface


                  Public Class MyControl
                  Implements IDotNetActiveX


                  Private Sub MyControl_Load( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
                  Txt_MyTextBox.T ext = "This is some text loaded in the page Load event...."
                  End Sub

                  Public ReadOnly Property MyString() As String Implements IDotNetActiveX. MyString
                  Get

                  Return "This is a String"
                  End Get
                  End Property
                  Public Sub LoadMe() Implements IDotNetActiveX. LoadMe
                  Txt_MyTextBox.T ext = "This is some text loaded in the page Load event...."
                  End Sub
                  Public Sub New()

                  ' This call is required by the Windows Form Designer.
                  InitializeCompo nent()

                  ' Add any initialization after the InitializeCompo nent() call.

                  End Sub

                  End Class[/code]

                  And in the ASP.NET portion I call the .NET ActiveX.

                  [code=asp]
                  <object id="testDotNetA ctiveX" name="testDotNe tActiveX" classid="~/Bin/DotNetActiveXCo ntrol.dll#DotNe tActiveXControl .MyControl" height="300px" width="300px" onclick="doSome thing();return false;"></object>
                  [/code]
                  [code=javascript]
                  <script type="text/javascript">
                  function doSomething()
                  {
                  aspnetForm.test DotNetActiveX.L oadMe();
                  /*aspnetForm is the name of the Form that my control is located in*/
                  }
                  </script>
                  [/code]

                  I've also tried moving this to an IIS Server and setting the lesser restrictions on the "Bin" directory (where the resource has been included).

                  There has to be something I'm over looking!

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Well I did notice that your class there doesn't have ang UI associated with it?
                    Mine is:
                    public partial class myControl : UserControl, AxMyControl

                    So it hase the UI associated with being a UserControl, you don't inhereit from that so maybe that is why nothing is showing up?

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Originally posted by Plater
                      Well I did notice that your class there doesn't have ang UI associated with it?
                      Mine is:
                      public partial class myControl : UserControl, AxMyControl

                      So it hase the UI associated with being a UserControl, you don't inhereit from that so maybe that is why nothing is showing up?
                      Ok that's kind of strange...I never noticed that before.

                      I didn't develop my control based on a Web User Control...I developed it based on a User Control (windows desktop application). Perhaps the partial class implementation is specific to Web User Controls?

                      For instance, where in a desktop UI would you set the CodeFile attribute that you would set in the Page directive of a Web User Control in order to specify what file the implementation is stored in????


                      Did you use a Web User Control? Or a User Control?

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        Originally posted by Plater
                        So it hase the UI associated with being a UserControl, you don't inhereit from that so maybe that is why nothing is showing up?
                        Something is showing up...the TextBox shows up. But none of the text shows up in the control...the text is set in the Load event...and also in the LoadMe method.

                        Comment

                        • Plater
                          Recognized Expert Expert
                          • Apr 2007
                          • 7872

                          #13
                          I was using regular user control, which is why i asked because yours is just "class"?

                          Comment

                          • Frinavale
                            Recognized Expert Expert
                            • Oct 2006
                            • 9749

                            #14
                            Originally posted by Plater
                            I was using regular user control, which is why i asked because yours is just "class"?
                            I just created a new user control to double check that I hadn't deleted something by accident.

                            The code for User Controls is just a simple Public Class...apparen tly....

                            Comment

                            Working...