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>" width="<width>"> <PARAM NAME="<property-name>" VALUE="<property-value>"> </OBJECT> IE places the following constraints when hosting .NET controls within the browser:
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 IconButton1: <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="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/ intellisense/ie5"> 10: </head> 11: <body MS_POSITIONING="GridLayout"> 12: <form method="post" runat="server"> 13: <object classid= "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. |