title: ASP.Net Server Control with a GridView control as a property
body: <p>I'm creating a custom server control that works in conjunction with a GridView control.  I have the following bit of code within my server control that defines the GridView control:</p>
  
  <pre><code>[Category("Data")]
  [Description("The associated GridView control")]
  public GridView GridViewControl { get; set; }
  </code></pre>
  
  <p>When I am in the designer and I drag and drop my control onto the surface and look at its properties in the property window I can see where it says "GridViewControl" and next to it where I can type the ID of a GridView control there is a dropbox from which I can select a GridView control that is already part of the page.  Selecting a GridView control from the dropbox genterates the following code:</p>
  
  <pre><code>&lt;cc1:MyCustomControl runat="server" ID="MyCustomControl1" GridViewControl="GridView1" /&gt;
  &lt;asp:GridView runat="server" ID="GridView1" ...
  </code></pre>
  
  <p>So everything looks good at design time.  However if I try to run the code then the app crashes because it is unable to convert the string name "GridView1" into a reference to the object GridView1.</p>
  
  <p>I'm assuming that this is because I'm missing some sort of code that I need to include in my custom server control code but I haven't been able to find any examples of such a server control.  Is this indeed my problem or is there something else or more that I'm missing in my code for things to work properly at run-time?</p>