Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Custom Composite Server Control Children not visible to the designer

Custom Composite Server Control Children not visible to the designer

Scheduled Pinned Locked Moved ASP.NET
helphtmlcsssysadmin
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SlingBlade
    wrote on last edited by
    #1

    I'm developing a TabStrip control and am having a bit of an issue with the designer and child controls. Below is the relevant code in regards to the problem (I can provide more if needed).

    \[ParseChildren(true), PersistChildren(false)\]
    \[ToolboxData("<{0}:TabStrip runat=server></{0}:TabStrip>")\]
    public class TabStrip : CompositeControl, IPostBackEventHandler
    {
        private Tab mySelectedTab;
        private TabCollection myTabs;
        
        public TabStrip()
        {
            this.myTabs = new TabCollection(this);
        }
        
        \[MergableProperty(false)\]
        public Tab SelectedTab
        {
            get
            {
                foreach (Tab tab in this.Tabs)
                    if (tab.IsSelected)
                        return tab;
                return null;
            }
            set { value.IsSelected = true; }
        }
        
        \[PersistenceMode(PersistenceMode.InnerProperty), NotifyParentProperty(true)\]
        \[MergableProperty(false)\]
        public TabCollection Tabs
        {
            get { return myTabs; }
        }
    }
    

    When I add tabs to the Tabs property on a page using the property grid's collection editor the tabs are listed in the collection editor by ID and can also be selected from a drop-down list from the property grid for the SelectedTab property. This is good and is exactly how I want the control to behave in the designer. The problem is, when the page is closed and reopened in the designer, the markup is still there, but when editing the child tabs in the collection editor they are listed by there class name rather than ID, changes made in the collection editor are not persisted, and they are no longer listed in the drop-down for the SelectedTab property. This is no good. The TabCollection class implements the IList interface and all the Tab's public properties have the NotifyParentPropertyAttribute set to true. Please advise as to what may be missing for the designer to be aware of the child controls when the page containing the control is reopened. Thank you.

    C N 2 Replies Last reply
    0
    • S SlingBlade

      I'm developing a TabStrip control and am having a bit of an issue with the designer and child controls. Below is the relevant code in regards to the problem (I can provide more if needed).

      \[ParseChildren(true), PersistChildren(false)\]
      \[ToolboxData("<{0}:TabStrip runat=server></{0}:TabStrip>")\]
      public class TabStrip : CompositeControl, IPostBackEventHandler
      {
          private Tab mySelectedTab;
          private TabCollection myTabs;
          
          public TabStrip()
          {
              this.myTabs = new TabCollection(this);
          }
          
          \[MergableProperty(false)\]
          public Tab SelectedTab
          {
              get
              {
                  foreach (Tab tab in this.Tabs)
                      if (tab.IsSelected)
                          return tab;
                  return null;
              }
              set { value.IsSelected = true; }
          }
          
          \[PersistenceMode(PersistenceMode.InnerProperty), NotifyParentProperty(true)\]
          \[MergableProperty(false)\]
          public TabCollection Tabs
          {
              get { return myTabs; }
          }
      }
      

      When I add tabs to the Tabs property on a page using the property grid's collection editor the tabs are listed in the collection editor by ID and can also be selected from a drop-down list from the property grid for the SelectedTab property. This is good and is exactly how I want the control to behave in the designer. The problem is, when the page is closed and reopened in the designer, the markup is still there, but when editing the child tabs in the collection editor they are listed by there class name rather than ID, changes made in the collection editor are not persisted, and they are no longer listed in the drop-down for the SelectedTab property. This is no good. The TabCollection class implements the IList interface and all the Tab's public properties have the NotifyParentPropertyAttribute set to true. Please advise as to what may be missing for the designer to be aware of the child controls when the page containing the control is reopened. Thank you.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The designer is evil. Do not use it.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      S 1 Reply Last reply
      0
      • C Christian Graus

        The designer is evil. Do not use it.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        S Offline
        S Offline
        SlingBlade
        wrote on last edited by
        #3

        But I like the designer. Besides, this is a TabStrip that I intend to share. There must be something I'm missing that the CollectionEditor does to make the designer aware of the controls it added that I could implement in the control, but I have no idea what.

        1 Reply Last reply
        0
        • S SlingBlade

          I'm developing a TabStrip control and am having a bit of an issue with the designer and child controls. Below is the relevant code in regards to the problem (I can provide more if needed).

          \[ParseChildren(true), PersistChildren(false)\]
          \[ToolboxData("<{0}:TabStrip runat=server></{0}:TabStrip>")\]
          public class TabStrip : CompositeControl, IPostBackEventHandler
          {
              private Tab mySelectedTab;
              private TabCollection myTabs;
              
              public TabStrip()
              {
                  this.myTabs = new TabCollection(this);
              }
              
              \[MergableProperty(false)\]
              public Tab SelectedTab
              {
                  get
                  {
                      foreach (Tab tab in this.Tabs)
                          if (tab.IsSelected)
                              return tab;
                      return null;
                  }
                  set { value.IsSelected = true; }
              }
              
              \[PersistenceMode(PersistenceMode.InnerProperty), NotifyParentProperty(true)\]
              \[MergableProperty(false)\]
              public TabCollection Tabs
              {
                  get { return myTabs; }
              }
          }
          

          When I add tabs to the Tabs property on a page using the property grid's collection editor the tabs are listed in the collection editor by ID and can also be selected from a drop-down list from the property grid for the SelectedTab property. This is good and is exactly how I want the control to behave in the designer. The problem is, when the page is closed and reopened in the designer, the markup is still there, but when editing the child tabs in the collection editor they are listed by there class name rather than ID, changes made in the collection editor are not persisted, and they are no longer listed in the drop-down for the SelectedTab property. This is no good. The TabCollection class implements the IList interface and all the Tab's public properties have the NotifyParentPropertyAttribute set to true. Please advise as to what may be missing for the designer to be aware of the child controls when the page containing the control is reopened. Thank you.

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Getting collection editors work correctly with designer is not trivial. Please take a look at my article and source code associated : XP Style Navigation Bar Server Control with collection property and embedded resources[^].

          Navaneeth How to use google | Ask smart questions

          S 1 Reply Last reply
          0
          • N N a v a n e e t h

            Getting collection editors work correctly with designer is not trivial. Please take a look at my article and source code associated : XP Style Navigation Bar Server Control with collection property and embedded resources[^].

            Navaneeth How to use google | Ask smart questions

            S Offline
            S Offline
            SlingBlade
            wrote on last edited by
            #5

            Thanks, I added the [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] attribute and that fixed the changes issues (It was there before but I removed it thinking it rendundant to the PersistanceMode, oops). I ended up making a custom UITypeEditor to list the child tabs for the SelectedTab property. That brought to my attention a flaw to the logic of setting that property in the designer since it doesn't know how to persist a control value by it's ID. So I ended up setting the [Browsable(false)] attribute on the SelectedTab property and implementing a SelectedTabID property and using the custom UITypeEditor for that property. It is a bit of a workaroung but all is well now. I know I've seen a TypeConverter or something out there that can be used to list control ids of a certain type, but can't recall how, nor do I think it would work since the designer is still unaware of the child controls unless added with the CollectionEditor. Thanks for pointing me to your article, looks like a cool control. I'll have to look closer even though I have already implemented a solution.

            N 1 Reply Last reply
            0
            • S SlingBlade

              Thanks, I added the [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] attribute and that fixed the changes issues (It was there before but I removed it thinking it rendundant to the PersistanceMode, oops). I ended up making a custom UITypeEditor to list the child tabs for the SelectedTab property. That brought to my attention a flaw to the logic of setting that property in the designer since it doesn't know how to persist a control value by it's ID. So I ended up setting the [Browsable(false)] attribute on the SelectedTab property and implementing a SelectedTabID property and using the custom UITypeEditor for that property. It is a bit of a workaroung but all is well now. I know I've seen a TypeConverter or something out there that can be used to list control ids of a certain type, but can't recall how, nor do I think it would work since the designer is still unaware of the child controls unless added with the CollectionEditor. Thanks for pointing me to your article, looks like a cool control. I'll have to look closer even though I have already implemented a solution.

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              Good. Let me know if you find any flaws in the code.

              Navaneeth How to use google | Ask smart questions

              S 1 Reply Last reply
              0
              • N N a v a n e e t h

                Good. Let me know if you find any flaws in the code.

                Navaneeth How to use google | Ask smart questions

                S Offline
                S Offline
                SlingBlade
                wrote on last edited by
                #7

                Will do.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups