Aspnet Control Development 11 VB

To build the assembly containing this new class, create a file called makevb.bat and enter the following commands:

set outdir=..\..\bin\MyFirstControlInVB.dll set assemblies=System.dll,System.Web.dll vbc /t:library /out:%outdir% /r:%assemblies% MyFirstControllnVB.vb

Again, substitute the '..' in the first line to point to your virtual directory.

This is similar to the C# make file except that the compiler name is now vbc rather than csc, and the output file is

MyFirstControlInVB.dll.

Run the make file to compile the control, then bring up your text editor and enter the following ASP.NET page code, and save it:

<%@ Register TagPrefix="Wrox" Namespace="WroxControls" Assembly="MyFirstControlInVB" %>

<Wrox:MyFirstControlInVB runat="server" />

The page is pretty much identical to the ASP.NET page that used the C# version of the control, but we have changed the assembly directive and line in the <body> element to specify the class MyFirstControllnVB instead of

MyFirstControl.

Two Controls on One Page

After you have viewed the page to prove your VB control is working, update the page with the additional lines shown here:

<%@ Register TagPrefix="Wrox" Namespace="WroxControls"

Assembly="MyFirstControlInVB" %> <%@ Register TagPrefix="WroxCSharp" Namespace="WroxControls" Assembly="MyFirstControl" %>

<Wrox:MyFirstControlInVB runat="server" />

<WroxCSharp:MyFirstControl runat="server" />

The additional register directive associates the assembly containing the C# control with the tag prefix WroxCSharp. Since the controls we're using on this page are in different assemblies, we have to do this. If two controls were in the same assembly, we'd only need one directive.

View this updated page in the browser and you should see the output from the two controls:

3hltp://Jo£aihost servercontMls/smple/vl, myF^steofttroLaspH -

p(g Edit View Favorites Tqot Help

Bad! - ' ¡Q ¿JJ {E Personal ÖSear:il LäFs,rtlrite5 # ^ 3 ^

A^dresi http://localhü5t/ser\örcontrcls/iinnfileyvb/miyftiätcür.trül.äip

0 0

Post a comment