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

Hosting .NET UserControl in Internet Explorer

Hello experts

I'm having a problem in hosting a .NET control within Internet Explorer.  I've followed numerous samples to the letter, and even downloaded example code.  I always seem to be hitting the same problem in that, where the .NET control should be, there is an image placeholder in its place.

I had previously had a text-box in it's place but, resolved that by changing the execution permissions to "Scripts Only" within IIS, as opposed to "Scripts and Executables".

The server where the page & control is hosted IS in the trusted sites, and I've tried it on a remote IIS server on the LAN, as well as running it from the local machine.  I've tried hosting the control in IIS on Windows XP, Windows 2000, as well as using IE6 from Windows 2000 / XP as a client.  All combinations give the same result.

Any advice as to what I'm doing wrong would be greatly appreciated.

Kind Regards

1 Solution
I'm a little confused here. You don't really host a .NET user control. A user control (.ascx) is a custom control and can be used to plug a common set of elements in to a page. You use it almost the exact same way as you'd use a textbox, but since it's custom, it needs to be registered at the top of the page in the page directives.

What does the user control do? Can you post it here and how you're using it?

In theory, you could create a user control that just displays an image. So it's hard to diagnose what the problem is without more information.
hairymingaAuthor Commented:
Ah, sorry for the confusion.  I was meaning a WinForms control, not an ASP.NET user control.  It's similar functionality to ActiveX that I'm looking for.

I've created a WinNT service that connects to an ACD server in our call center (which doesn't normally offer very good realtime stats) and used the events raised from the server to create a true realtime statistics service.  I have client applications that are written in VB.NET that connect to the service and subscribe to these realitime statistics.  I'm hoping to get the same functionality from within a web page, so that I can have an ASP.NET information service that projects various details onto a collection of plasma screens around the building.

I've achieved something similar to this using an elaborate solution with an extra service on the IIS server, and AJAX but, I'd much rather code a WinForms control that will offer the statistics in realtime, and avoid having to introduce extra services, thereby creating extra points where the whole process can fall over.
hairymingaAuthor Commented:
And, to give you an idea of what I've attempted:

Within VS.NET (although I'm actually using #Develop), create a new User Control project in VB.NET, calling the project "HelloWorldControl" with one user control, called HelloWorldCtl

Here's the code for HelloWorldCtl:

Public Class HelloWorldCtl
      Inherits System.Windows.Forms.UserControl
      Public Sub New()
            ' The Me.InitializeComponent call is required for Windows Forms designer support.
            ' TODO : Add constructor code after InitializeComponents
      End Sub
      Sub CmdClickClick(ByVal sender As Object, ByVal e As EventArgs)
            lblMessage.Text = "Hello, World"
      End Sub
      #Region " Designer Generated Code "
      Private components As System.ComponentModel.IContainer

      Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                  If components IsNot Nothing Then
                  End If
            End If
      End Sub
      Private Sub InitializeComponent()
            Me.lblMessage = New System.Windows.Forms.Label
            Me.cmdClick = New System.Windows.Forms.Button
            Me.lblMessage.Location = New System.Drawing.Point(8, 8)
            Me.lblMessage.Name = "lblMessage"
            Me.lblMessage.Size = New System.Drawing.Size(224, 23)
            Me.lblMessage.TabIndex = 0
            Me.lblMessage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            Me.cmdClick.Location = New System.Drawing.Point(8, 32)
            Me.cmdClick.Name = "cmdClick"
            Me.cmdClick.Size = New System.Drawing.Size(224, 23)
            Me.cmdClick.TabIndex = 1
            Me.cmdClick.Text = "Click Me"
            Me.cmdClick.UseVisualStyleBackColor = true
            AddHandler Me.cmdClick.Click, AddressOf Me.CmdClickClick
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.Name = "HelloWorldCtl"
            Me.Size = New System.Drawing.Size(242, 65)
      End Sub
      Private cmdClick As System.Windows.Forms.Button
      Private lblMessage As System.Windows.Forms.Label

      #End Region

End Class

The code compiles fine, and works when used in a .NET WinForms application.  Clicking the button places the text "Hello, World" into the label as expected.

I've created a virtual directory in an IIS 5.0 & IIS 6.0 server, called "HelloWorldControlHost" and, set the execution permissions to "Scripts Only" (as advised in various tutorials).  I've placed the resultant DLL from the above code (HelloWorldControl.dll) into the directory that holds the virtual path "HelloWorldControlHost", as well as placed "hello.html" (with the HTML code below).  When browsing the server with http://<server address>/HelloWorldControlHost.html i get the correct page, with no control.  Instead there's a placeholder there like as though Internet Explorer was trying to load an image file (jpg, gif etc).  If I change the execute permissions to "Scripts and Executables" then the same page gives me a textbox instead of the control, as warned in the tutorials.

Not sure if there's something I've misconfigured but, as stated, I've followed numerous tutorials to the letter, with no joy!

HTML Code from hello.html:

<p>Hello World Control<br> <br>
<object id="HelloWorldControl1" classid="http:HelloWorldControl.dll#HelloWorldControl.HelloWorldCtl" height="500" width="500" VIEWASTEXT>
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

I see that you've read through many tutorials... but I don't see anything stating that you've setup a .NET code access group policy..

You need to set these security settings so IE knows where it can execute .NET code from a remote location safely..

Check this out..

Try this..
Go to the .NET configurations wizard  (Should be in administrative tools)
expand My Computer/Runtime Security Policy/Machine/Code Groups/All_Code. Right click/New and create a new Code Group with the following properties:
Name: HelloWorldControl
Condition Type: URL
URL= http://localhost/*
Permission set: FullTrust

This should give you permission to use your control.  Please let me know if you've tried anything similar to this.

Hope it helps.
zephyr_hex (Megan)DeveloperCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
"Accept bobbyrellis's comment as answer."

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

zephyr_hex Experts Exchange Cleanup Volunteer
Forced accept.

EE Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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