Designer visibility of templated server control children

Last post 11-04-2007 10:33 PM by Nai-Dong Jin - MSFT. 1 replies.

Sort Posts:

  • Designer visibility of templated server control children

    11-02-2007, 3:07 PM
    • Member
      point Member
    • ScottyMac
    • Member since 11-02-2007, 6:58 PM
    • Posts 1

    Hello World,

     I have templated custom server control, which works ok, but the visual studio designer
    cannot properly "see" the child controls within the template, for code-behind work and the such.

     <cc1:mycontrol runat="server">
      <template>
        <asp:label runat="server" id="mylabel">
      </template>
    </cc1:mycontrol>

    If i set the PersistChilden/ParseChildren one way (false/true), visual studio does not "see" the MyLabel
    control and gives an undefined variable compile error.  If I set them the other way (true/false), then i
    can no longer use FindControl to find Mylabel by searching the page control hierarchy.

    Any hints on how to get both methods to work?

     

  • Re: Designer visibility of templated server control children

    11-04-2007, 10:33 PM
    Answer

    Hi,

    I have templated custom server control, which works ok, but the visual studio designer
    cannot properly "see" the child controls within the template, for code-behind work and the such.

    From your description, it seems that you are unable to see the child controls you create in design form, right?

    Generally, the cause of this kind of problem is that you haven’t add the ControlDesigner declaration in your custom control’s class level. See the following code snippet:
    namespace ASP.NET
    {

    [Designer("System.Web.UI.Design.ControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
    public class CustomControl : WebControl
        {
            Table t;
             ….

    Thanks.

    Michael Jin.
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (2 items)