locked
Server Control with container RRS feed

  • Question

  • User63780355 posted

     Hi,

    I need server control, which going to have following markup:

    <cc1:CustomPanel ID="Panel1" runat="server">

    <ContentTemplate>

       <asp:TextBox ID="txtTest1" Text="Test" runat="server"></asp:TextBox>

       <asp:TextBox ID="txtTest2" Text="Test" runat="server"></asp:TextBox>

    </ContentTemplate> 

    </cc1:CustomPanel >      

    txtTest1 and txtTest2 needs to be accesible from a page, So, I used PlaceHolder instead of ITemplate like this:

    [Browsable(false)]
    [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [EditorBrowsable(EditorBrowsableState.Never)]        
    public PlaceHolder ContentTemplate
    {
        get { return _contentTemplate; }
        set { _contentTemplate = value; }
    }

     The problem is in Design View. When I start typing inside of my CustomPanel it doesn't create

    ContentTemplate tag automatically, so source view looks like this:
     <cc1:CustomPanel ID="Panel1" runat="server">
    <br/></br> 
    </cc1:CustomPanel>
    instead of 
     <cc1:CustomPanel ID="Panel1" runat="server">
    <ContentTemplate>
    <br/></br>
    </ContentTemplate>
    </cc1:CustomPanel>
    Of course I can create  <ContentTemplate> tag in source view and then edit content in design view (I even have Intellissence for this).
    Is there a way to force Visual Studio to create ContentTemplate tag in Design View?

    Thursday, July 24, 2008 12:08 PM

Answers

  • User63780355 posted

     Hi,

    Probably something wrong with my implementation, but Visual Studio thinks that whole control is ContentTemplate. So, even Border tag apears inside of ContentTemplate.

    I managed to rewrite:

    GetEditableDesignerRegionContent(EditableDesignerRegion region)
    
    SetEditableDesignerRegionContent(EditableDesignerRegion region, string content)
      one more time in order to support Border. Now more or less everything is working.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 30, 2008 10:28 AM

All replies

  • User-1136466523 posted

    Hi,

    As for the Intellisense, it is controlled by the certain XML schema setting of Visual Studio IDE. ASP.NET built-in server controls have internal XML schema associated with them. For custom web server control, you may add your custom schema:

    #Adding Design-Time Support to ASP.NET Controls
    http://msdn.microsoft.com/en-us/library/aa478960.aspx

    #How to add a custom intellisense and validation schema to Visual Web Developer 2005
    http://blogs.msdn.com/mikhailarkhipo...01/522614.aspx

    Thanks.

    Tuesday, July 29, 2008 12:57 AM
  • User63780355 posted

     Thank you for your links. It is interesting information, hower in my case Intellisense is working. Design view is not. I managed to fix problem by overriding ContainerControlDesigner  methods:

    GetEditableDesignerRegionContent(EditableDesignerRegion region)

    SetEditableDesignerRegionContent(EditableDesignerRegion region, string content)
     
    However now I can't use other properties, not container kind of properties. They do not generate any markup on aspx page, however they change Design View.
    As an example is CustomPanel border color. It suppose to generate following tag <Border Color="#FF00FF" />  in:

    <cc1:CustomPanel ID="Panel1" runat="server">

    <Border Color="#FF00FF" /> 

    <ContentTemplate>

       <asp:TextBox ID="txtTest1" Text="Test" runat="server"></asp:TextBox>

       <asp:TextBox ID="txtTest2" Text="Test" runat="server"></asp:TextBox>

    </ContentTemplate> 

    </cc1:CustomPanel >    

    Border is instance of  CustomBorder class. It is public property of CustomPanel.

           [Category("Appearance")]
            [TypeConverter(typeof(SectionStyleObjectConverter))]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            [PersistenceMode(PersistenceMode.InnerProperty)]                       
            public CustomBorder Border
            {
                get
                {
                    return _border;
                }
                set
                {
                    _border = value;
                }
            }

       If I remove [Designer(typeof(ExtendedContainerControlDesigner))] from my CustomPanel declaration than Border is generated, so
    it's obviously that something needs to be overriden in  ContainerControlDesigner.
    Tuesday, July 29, 2008 9:49 AM
  • User63780355 posted

     Hi,

    Probably something wrong with my implementation, but Visual Studio thinks that whole control is ContentTemplate. So, even Border tag apears inside of ContentTemplate.

    I managed to rewrite:

    GetEditableDesignerRegionContent(EditableDesignerRegion region)
    
    SetEditableDesignerRegionContent(EditableDesignerRegion region, string content)
      one more time in order to support Border. Now more or less everything is working.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 30, 2008 10:28 AM