• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

How to use a usercontrol on a web page in asp.net vs2008

I have developed a usercontrol that provides access to a check scanner and returns the MICR line and an image of the check. This control is developed using visual studio 2008 and has been fully tested and works in a windows form. The problem is, I need to have it work on a web page. I basically need this to work like an activex control and I think I am missing something critical for this to work.

As it is, if I place the control on a web page, I see nothing in either the designer or when I run/view the web page.
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;
using RDMCOLib;
using RDMTIFFLib;
 
namespace ChkScanner
{
    public delegate void _IDataCompleteEvent();
 
    public interface AxScanControl
    {
        string AccountNumber { get; }
        string RoutingNumber { get; }
        string CheckNumber { get; }
        string RawMICR { get; }
        string ImageLocation { set; }
        string StoreNumber { set; }
        string ImageName { get; }
        int ConnType { get; set; }
        _IDataCompleteEvent OnScanComplete { set; }
    }
 
    public partial class ScanControl : UserControl, AxScanControl 
    {
        public event _IDataCompleteEvent ScanComplete;
 
        public ScanControl()
        {
            InitializeComponent();
            this.Show();
            this.Update();
        }
 
        private string _accountNumber = "";
        public string AccountNumber
        {
            get { return _accountNumber; }
        }
 
        private string _routingNumber = "";
        public string RoutingNumber
        {
            get { return _routingNumber; }
        }
 
        private string _checkNumber = "";
        public string CheckNumber
        {
            get { return _checkNumber; }
        }
 
        private string _rawMICR = "";
        public string RawMICR
        {
            get { return _rawMICR; }
        }
 
        private string _imageLocation = "";
        public string ImageLocation
        {
            set { _imageLocation = value; }
        }
 
        private string _storeNumber = "";
        public string StoreNumber
        {
            set { _storeNumber = value; }
        }
 
        private string _imageName = "";
        public string ImageName
        {
            get { return _imageName; }
        }
 
        private int _connType = 0;
        public int ConnType
        {
            get { return _connType; }
            set { _connType = value; }
        }
 
        public _IDataCompleteEvent OnScanComplete
        {
            set { ScanComplete += new _IDataCompleteEvent(value); }
        }
 
        RDMOPOS oScanner = new RDMOPOS();   // create new instance of the scanner object
        private int nReturnCode = 0;
 
        private const int OPOS_SUCCESS = 0;
        private const int OPOS_S_CLOSED = 1;
        private const int OPOS_S_IDLE = 2;
        private const int OPOS_S_BUSY = 3;
 
        private const int RDMPOS_CFG_CAPTUREMODE = 0x6F09;
        private const int RDMPOS_CAPTUREMODE_DEFAULT = 0x71;
        private const int RDMPOS_CFG_OCR = 0xCF03;
        private const int RDMPOS_OCRSOURCE_NONE = 0x00;
        private const int RDMPOS_OCRSOURCE_ALLMICRCHARS = 0x02;
        private const int RDMPOS_OCRSOURCE_UNRECOG = 0x04;
        private const int RDMPOS_OCRCOMBINE_NONE = 0x00;
        private const int RDMPOS_OCRCOMBINE_UNRECOG_USEOCR = 0x01;
 
        private void oScanner_DataEvent(int rStatus)
        {
            if (rStatus == 0)
            {
                // save the route, account, and check numbers read - also save the rawdata returned
                _accountNumber = oScanner.AccountNumber;
                AccountNo.Text = oScanner.AccountNumber;
                _routingNumber = oScanner.TransitNumber;
                RouteNo.Text = oScanner.TransitNumber;
                _checkNumber = oScanner.CheckNumber;
                CheckNo.Text = oScanner.CheckNumber;
                _rawMICR = oScanner.RawData;
                RawMicr.Text = oScanner.RawData;
            }
            if (rStatus == 1)
            {
                // scanner read was successful, now grab the image and save it
                if ((oScanner.ImageSize > 0) && !string.IsNullOrEmpty(_imageLocation))
                {
                    MessageBx.Text = "Saving Image...";
                    this.Update();
                    oScanner.GetImage(-1, false);
                    TIFF mTiff = new TIFF();
                    mTiff.LoadFromMemory(oScanner.ImageData, oScanner.ImageSize);
                    _imageName = _storeNumber + DateTime.Now.ToString("yyMMdd") + oScanner.IRN.Substring(oScanner.IRN.Length - 3) + ".tif";
                    string _saveLocation = _imageLocation + _imageName;
                    mTiff.UtilWriteToFile(mTiff.ImagePointer, mTiff.ImageSize, ref _saveLocation);
                    CheckImg.Load(_saveLocation);
                }
                ScannerCompleted();
            }
        }
 
        protected virtual void ScannerCompleted()
        {
            ScannerReset();
            CancelBtn.Enabled = false;
            ScanBtn.Enabled = true;
            MessageBx.Text = "DONE";
            this.Update();
            if (ScanComplete != null) ScanComplete();
        }
 
        private void ScanBtn_Click(object sender, EventArgs e)
        {
            string sDummy = "";
            int lparm = 0;
            CancelBtn.Enabled = true;
            ScanBtn.Enabled = false;
            MessageBx.Text = "Please Wait...";
            this.Update();
            if (oScanner.State != OPOS_S_BUSY)
            {
                AccountNo.Text = "";
                RouteNo.Text = "";
                CheckNo.Text = "";
                RawMicr.Text = "";
                CheckImg.ImageLocation = "";
                this.Update();
                try
                {
                    nReturnCode = oScanner.Close();     // make sure scanner is closed
                    if ((nReturnCode != 0) && (nReturnCode != 101)) throw new Exception("Close ERROR " + nReturnCode.ToString());
                    nReturnCode = oScanner.Open("RDMPOS");  // open scanner
                    if (nReturnCode != 0) throw new Exception("Open ERROR " + nReturnCode.ToString());
                    nReturnCode = oScanner.ClaimDevice(0);  // claim scanner device 0
                    if (nReturnCode != 0) throw new Exception("Claim ERROR " + nReturnCode.ToString());
                    if (!oScanner.DeviceEnabled)        // check to see if scanner is enabled
                    {
                        oScanner.ConnectionType = _connType; // set the connection type to 0=serial, 1=usb
                        oScanner.DeviceEnabled = true;  // enable the scanner
                        nReturnCode = oScanner.ResultCode;
                        if (nReturnCode != 0) throw new Exception("Conn ERROR " + nReturnCode.ToString());
                    }
                    oScanner.ClearInput();      // clear the scanners input
                    oScanner.ClearOutput();     // clear the scanners output - this line and previous effective resets the scanner and makes it ready
                    oScanner.OCRActive = true;         // turn on OCR
                    oScanner.OCRMicrDetect = true;      // turn on MICR
                    oScanner.MICRReadErrorHandling = 0; // MRE_NONE
                    oScanner.DataEvent += new _IRDMOPOSEvents_DataEventEventHandler(oScanner_DataEvent);
                    oScanner.DataEventEnabled = true;
                    lparm = RDMPOS_CAPTUREMODE_DEFAULT; // configure scanner for default capture mode (MICR and Image)
                    oScanner.SetConfiguration(RDMPOS_CFG_CAPTUREMODE, 0, sDummy, lparm);
                    nReturnCode = oScanner.ResultCode;
                    if (nReturnCode != 0) throw new Exception("Config ERROR " + nReturnCode.ToString());
                    lparm = RDMPOS_OCRSOURCE_UNRECOG * 256 + RDMPOS_OCRCOMBINE_UNRECOG_USEOCR;  //configure scanner to use OCR to fill in MICR errors
                    oScanner.SetConfiguration(RDMPOS_CFG_OCR, 0, sDummy, lparm);  // set micr ocr options
                    nReturnCode = oScanner.ResultCode;
                    if (nReturnCode != 0) throw new Exception("Config ERROR " + nReturnCode.ToString());
                    oScanner.ImageOptions = (oScanner.ImageOptions & 0xFFFE);   // don't automatically get the image
                    nReturnCode = oScanner.BeginInsertion(-1);  // starts scanner with no timeout
                    if (nReturnCode != 0) throw new Exception("Start ERROR " + nReturnCode.ToString());
                    MessageBx.Text = "Scanner is Ready";
                    this.Update();
                }
                catch (Exception ex)
                {
                    MessageBx.Text = ex.Message;
                    this.Update();
                }
            }
            else 
            {
                MessageBx.Text = "Scanner is Busy";
                ScanBtn.Enabled = true;
                CancelBtn.Enabled = false;
                this.Update();
            }
        }
 
        public void ScannerReset()
        {
            oScanner.ClearInput();      //reset the scanner by clearing the input and output channels
            oScanner.ClearOutput();
            oScanner.Close();           //close the scanner
        }
 
        private void CancelBtn_Click(object sender, EventArgs e)
        {
            ScannerReset();
            MessageBx.Text = "";
            ScanBtn.Enabled = true;
            CancelBtn.Enabled = false;
            this.Update();
        }
    }
}

Open in new window

0
batracy
Asked:
batracy
  • 4
  • 3
3 Solutions
 
Ted BouskillSenior Software DeveloperCommented:
Most experts avoid questions like this but I tend to try the tough ones.

First off, web applications are completely different than Windows in more ways than I think you realize.  A windows application has direct access to the computer running it.  A web page is hosted in a browser which does not allow the web page access to the computer hosting the web page.  That is to protect the client computer.

Windows controls and Web controls are completely different objects and not compatible due to the differences in how both work.

Do you mean you want to have a web page that is displayed on a computer access a local scanner or a remote scanner on a remote web server?
0
 
batracyAuthor Commented:
The web page displayed on the local computer needs access to a local scanner attached to the local computer. The scanner manufacturer has provided activex controls for accessing and controlling the scanner, but these controls are less than user friendly and need to be wrapped into user friendly control.  I have been able to establish access to the scanner via a web control (ascx) but the nature of the scanner code is event driven and when the data complete event fires, I haven't been able to find a way to cause a post back to the web page - so even though the scan data is available to the control in the code behind, I can't seem to get it to post back to the page and display to the user.

So my thought was maybe there is a way to use the "usercontrol" as developed above as an activex control on the web page, but this doesn't even display the control on the page. As you may have seen, I've created an interface section to exposed it to com and it would be ideal if this control would load and work because it keeps things client side.

Anyway, any thoughts or help with this is greatly appreciated.
0
 
Ted BouskillSenior Software DeveloperCommented:
Web applications are terrible candidates for complex UI's because they are stateless and designed to have minimal interaction with the host operating system of the web server.

I would strongly recommend you simply do this as a windows application and override the UI that way.  It's far easier.  You can do far more with a Windows application than you can with a Web application.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
batracyAuthor Commented:
I don't think I understand what you are referring to - what do you mean override the UI that way? Can you provide some examples?
0
 
Ted BouskillSenior Software DeveloperCommented:
I can't provide detailed examples without having the scanner and it's API on my system.

You should be able to load the ActiveX controls in your windows application without displaying them.  You stated you are not happy with the UI for the ActiveX controls from the scanner company.  You can then use your own code to work with the ActiveX controls.  Basically do what you are attempting with the web page in a windows application.
0
 
batracyAuthor Commented:
That's not going to work as the company has an existing web site that this control I've been working on needs to be embedded into and return data to.

I'm attempting to redevelop the control as a web control to see if I can have any better luck in getting it to work. I was close with the ascx version, so we'll see if this can be done as a web control library (dll).
0
 
batracyAuthor Commented:
We have decided to go a different route on this.  Thanks everyone for your assistance.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

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