title: ASP .net : register custom control from .vb code
body: <p>I try to create custom control, loaded dynamically from .vb code.</p>
  
  <p>Here is my custom control "ControlCar" in file "controlcar.ascx"</p>
  
  <pre><code>&lt;%@ Control Language="VB" ClassName="ControlCar" %&gt;
  &lt;script runat="server"&gt;
      Private m_car As Car = Nothing
      Public Property Car() As Car
          Get
              Car= m_car
          End Get
          Set(ByVal value As Car)
              m_car = value
          End Set
      End Property
  
      Protected Sub Panel_OnLoad(ByVal sender As Object, ByVal e As System.EventArgs)
          If Me.m_car Is Nothing Then
              lit_color.Text = "(m_car Is Nothing)"
          Else
              lit_color.Text = "color of Me.m_car is (" &amp; Me.m_car.Color &amp; ")"
          End If
      End Sub
  
  &lt;/script&gt;
  
  &lt;asp:Panel ID="panel" OnLoad="Panel_OnLoad" runat="server"&gt;
      this is a car&lt;br /&gt;
      color = &lt;asp:Literal ID="lit_color" runat="server"&gt;&lt;/asp:Literal&gt;&lt;br /&gt;
      &lt;br /&gt;
  &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>Here is my ASP web page in file "cars.aspx" which use .vb code for events, ...</p>
  
  <pre><code>&lt;%@ Page Language="vb" Explicit="true" Inherits="PageBase" Src="/code/cars.vb"%&gt;
  
  &lt;html&gt;
  &lt;body&gt;
      &lt;!-- Html code here ---&gt;
      &lt;asp:panel ID="panel_cars" runat="server"&gt;
      &lt;/asp:panel&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>And here is my .vb code in file "cars.vb"</p>
  
  <pre><code>    Private Sub CreateCar()
          Dim car As Car = new Car()
          Dim control As ControlCar = Nothing
          control= CType(LoadControl("/code/controlcar.ascx"), ControlCar)
          control.Car = car
          panel_cars.Controls.Add(control)
      End Sub
  </code></pre>
  
  <p><strong>But it fails, saying 'ControlCar' is unrecognized</strong> in cars.vb.</p>
  
  <p>I know it works, if move .vb code in .aspx file and using directive</p>
  
  <pre><code>&lt;%@ Register TagPrefix="uc" TagName="ControlCar" Src="/code/controlcar.ascx" %&gt;
  </code></pre>
  
  <p>But I need to separate .vb code and .aspx code like in my example.</p>
  
  <p>How can I make recognizing 'ControlCar' type (defined in .ascx) in .vb file?</p>