?
Solved

ActiveX Object to receive command from web page to send to receipt printer.

Posted on 2009-04-20
9
Medium Priority
?
387 Views
Last Modified: 2013-11-18
Hello All,

I currently have a Windows forms application which interfaces with our receipt printer.  I would like to know if it's possible to write a C#.NET ActiveX object to be embedded in an aspx web page which would handle the printing of a receipt from within the web page.

For example:

Staff member enters payment information
System processes payment and redirects staff member's browser to finish page
ActiveX object embedded on the page processes the information and then generates the receipt and forwards it to the receipt printer.

I'm sure this is possible, but needing a good head-start into it.

I'd most appreciate a code sample of an activex object which could basically function similar to the description above.

Thanks
Anubis.
0
Comment
Question by:Anubis2005
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:Gorkem Yuksel
ID: 24184818
Hi,

Creating an activeX control is actually quite simple.  You have to start by creating a Windows Form control, and in the properties, checkmark the the COM / Interop setting.  This will allow it to function under native COM modes as well as the .NET platform.

The remainder of the control relies soley on creating and sending the document to the receipt printer.

Cheers,

G.
0
 
LVL 1

Author Comment

by:Anubis2005
ID: 24184924
Hi gyuksel,

Thanks for the reply, this is very encouraging!

When you say, create a windows form control, do you mean a Windows Forms Application or a Windows Forms Control Library?

When interfacing with the ActiveX object from the browser, say for example I wanted to pass the Receipt's ID into the ActiveX object when it's called, how would I do this?

Additionally, by checkmarking the COM/Interop setting, does this allow remote clients to be able to download the ActiveX object from the server serving the object or does the object have to be specifically installed on the client?

Thanks
Anubis.
0
 
LVL 9

Expert Comment

by:Gorkem Yuksel
ID: 24185018
Hi,

Yes, you will have to create a Windows From Control Library.. this will result in a DLL file that the browser will essentially download.

To communicate with the control, simply create public properties, methods and functions within your control library.  They can be called directly from your web front-end using VBscript or JavaScript.

Once you create the OBJECT in the HTML, the browser (IE) will automatically attempt the download.  You can provide a URL using the CODEBASE attribute.

Here is a quick and simple example:

<OBJECT id="myReceipt" name="myControl" classid="ActiveXDotNet.dll#ActiveXDotNet.myControl" width=288 height=72>
       </OBJECT>

<script language="javascript">
      function doScript()
       {
        myReceipt.PrintIt();
       }
</script>

Cheers,

G.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:Anubis2005
ID: 24185304
Excellent!

It'll will take me a few days to give it a test run, I'll keep this topic open till then.

Thanks very much for your assistance :)

Anubis.
0
 
LVL 1

Author Comment

by:Anubis2005
ID: 24238299
Hello gyuksel,

Thanks for the reply, however I'm still unable to get it to work properly.

Correct me if I'm wrong, using an activeX object allows me to execute a program as if it was an installed program running on the browser's PC?


I've created a 'Class Library' project and added a UserControl (named UserControl1).  This project is created using C#.  Is this correct?


Next, I've got the code (in snippet) in the user control.  The control simply consists of a button and a label (for testing).


Finally, on the web page, I've got:

<OBJECT id="myReceipt" name="myControl" classid="ActiveXProcessor.dll" width=288 height=72>
       </OBJECT>

<script language="javascript">
      function doScript()
       {
         document.getElementById("myReceipt").UserControl1();
       }
</script>
<span onclick="doScript()">Click Me</span>


I've tried setting the class ID to classid="ActiveXProcessor.dll#ActiveXProcessor.UserControl1" but this made no difference.  I added the DLL to the same folder that this page was running in and also in the /bin folder of the web app but no success.

All I get on the page is a white box will greyed out scroll bars and upon clicking 'Click Me' it says the methods are not found/invalid.

Thanks
Anubis
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace POSActiveXHelper
{
  public partial class UserControl1 : UserControl
  {
    public UserControl1()
    {
      InitializeComponent();
    }
 
    public void button1_Click(object sender, EventArgs e)
    {
      MessageBox.Show("Clicked");
    }
 
  }
}

Open in new window

0
 
LVL 9

Expert Comment

by:Gorkem Yuksel
ID: 24238360
You have to make sure that you've made your control visible to COM, otherwise it will not load.

I've attached a screenshot of where to find the setting for this.

In the project properties, under the application tab, click on the Assembly Information button and located at the bottom of the window, there is a check box that states "Make assembly COM-Visible".  If you don't checkmark this setting, the DLL will not have the proper "entry points" to register itself.

Cheers,

G.


ActiveX-Control-Setting.jpg
0
 
LVL 1

Author Comment

by:Anubis2005
ID: 24238394
Hi,

Thanks for the quick reply and continued assistance with getting this working.

I checked on this setting and it has been ticked already.

Additionally, under 'Build' register for COM interop is also checked.

Thanks.
Anubis.
0
 
LVL 9

Accepted Solution

by:
Gorkem Yuksel earned 2000 total points
ID: 24242433
Hi Anubis,

I've been able to do this in the past.. It definately took me a few tries to get it just right.. Here is what I had done to get it working.. Try the following steps: (i've included the code portions in the code window)

1/ Create a new Class Project
2/ Delete the Class1.cs file
3/ Add new item to the project (select User Control)
4/ Edit the Project properties
    - Application -> Assembly Information -> Checkmark Make Assembly COM-Visible
    - Build -> Checkmark Register for COM Interop
5/ Edit the UserControl1.cs code (right click on the cs file and select View Code)
6/ Add an Interface class to expose elements within your control to the browser
7/ Include the type of the Interface in your UserControl class
8/ Add code to handle the new interface
9/ Create new web project
10/ Add reference to the new control
11/ Add the <OBJECT> tag in your html code
12/ Copy the DLL file from the BIN directory into the main folder of your web project

Hope this helps.. you may need to tweak it just a little, but let me know if you need any additional help.

Cheers,

G.
ActiveX:
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
 
namespace MyActiveX1
{
    public interface myControl
    {
        string TextBoxText { get; set; }
    }
 
    public partial class MyUserControl : UserControl, myControl
    {
        private string _tb = "";
 
        public string TextBoxText
        {
            get { return _tb; }
            set
            {
                _tb = value;
                textBox1.Text = _tb;
            }
        }
 
        public MyUserControl()
        {
            InitializeComponent();
        }
    }
}
 
 
HTML:
<body onload="UpdateText()" >
<object id="ctrl1" name="ctrl1" classid="MyActiveX.dll#MyActiveX1.MyUserControl" width="150" height="150"></object>
 
    <script language="javascript">
    function UpdateText()
    {
        document.getElementById("ctrl1").TextBoxText = "This was updated from javascript";
    }
    </script>
</body>

Open in new window

0
 
LVL 1

Author Comment

by:Anubis2005
ID: 24276363
Yay!  It worked!  Thanks a million for your help.  

The problem came down to a simple case of mistyped namespaces.  I originally named the project "POSActiveXHelper" but later renamed it "POSActiveXProcessor" but forgot to update the namespace.  Doh!

Thanks again.
Anubis.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question