Hosting Controls in Internet Explorer

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); }

Internet Explorer (IE) supports the OBJECT tag for hosting classic ActiveX controls. In .NET, the OBJECT tag can be used to also host Windows Forms controls and provide accesses to the properties of the hosted control. For those of you familiar with hosting ActiveX controls, the syntax for the OBJECT tag will seem very familiar. The only difference is the CLASSID attribute used to identify the control to be created. The general form of the OBJECT tag is as follows:

 <OBJECT  CLASS height="<height>"  graphics/ccc.gifwidth="<width>">   <PARAM NAME="<property-name>" VALUE="<property-value>"> </OBJECT> 

IE places the following constraints when hosting .NET controls within the browser:

  • It requires Full-Trust for COM Interop (Event Handling).

  • The assembly must be in the current virtual directory or in the Global Assembly Cache.

  • Permissions for the virtual directory must be set to "Scripts only." Setting permissions to "Scripts & Executables" will not allow the control to be hosted.

As long as these conditions are met, hosting a control is a fairly simple process. Listing 10.5 shows a basic aspx page for hosting the IconButton developed earlier.

Listing 10.5 Hosting the IconButton
  1: <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"  graphics/ccc.gifInherits="IEIconButton.WebForm1" %>  2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >  3: <html>  4:     <head>  5:         <title>WebForm1</title>  6:         <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">  7:         <meta name="CODE_LANGUAGE" Content="C#">  8:         <meta name="vs_defaultClientScript" content="JavaScript">  9:         <meta name="vs_targetSchema" content= "http://schemas.microsoft.com/ graphics/ccc.gifintellisense/ie5"> 10:     </head> 11:     <body MS_POSITIONING="GridLayout"> 12:         <form  method="post" runat="server"> 13:           <object  classid=  graphics/ccc.gif"http:SAMS.ToolKit.dll#SAMS.ToolKit.Controls.IconButton" height="25" width="100" 14:           VIEWASTEXT> 15:             <param name="Text" value="Hello World"> 16:           </object> 17:         </form> 18:     </body> 19:  </html> 

The output produced from Listing 10.5 is shown in Figure 10.4.

Figure 10.4. Hosting the IconButton in Internet Explorer.

figure 10.4. hosting the iconbutton in internet explorer.



    .NET Windows Forms Custom Controls
    User Interfaces in VB .NET: Windows Forms and Custom Controls
    ISBN: 1590590449
    EAN: 2147483647
    Year: 2002
    Pages: 74

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net