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. Web Custom Control Question about Inheriting from a Panel

Web Custom Control Question about Inheriting from a Panel

Scheduled Pinned Locked Moved ASP.NET
designhelpquestionalgorithms
4 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.
  • R Offline
    R Offline
    Richard Parsons
    wrote on last edited by
    #1

    My code is shown below. My problem is that when I uses this code it displays just fine while running the webapp but when in design mode I see nothing other than a blank panel? I've been searching around google and cp and can't find any help so I have resorted to asking :) Any help would be appreciated. Public Class MyBar Inherits System.Web.UI.WebControls.Panel Protected Overrides Sub OnInit(ByVal e As System.EventArgs) EnsureChildControls() End Sub Dim _lbl As New Label Protected Overrides Sub CreateChildControls() _lbl.Text = "Hello World!" MyBase.Controls.Add(_lbl) End Sub Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter) MyBase.Render(output) End Sub End Class -Richard

    M 1 Reply Last reply
    0
    • R Richard Parsons

      My code is shown below. My problem is that when I uses this code it displays just fine while running the webapp but when in design mode I see nothing other than a blank panel? I've been searching around google and cp and can't find any help so I have resorted to asking :) Any help would be appreciated. Public Class MyBar Inherits System.Web.UI.WebControls.Panel Protected Overrides Sub OnInit(ByVal e As System.EventArgs) EnsureChildControls() End Sub Dim _lbl As New Label Protected Overrides Sub CreateChildControls() _lbl.Text = "Hello World!" MyBase.Controls.Add(_lbl) End Sub Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter) MyBase.Render(output) End Sub End Class -Richard

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Would this work for you: explicitly assign the PanelDesigner as your MyBar class' designer through the DesignerAttribute attribute?

      <Designer("System.Web.UI.Design.WebControls.PanelDesigner")> _
      Public Class MyBar
      Inherits System.Web.UI.WebControls.Panel
      . . .
      End Class

      R 1 Reply Last reply
      0
      • M Mike Ellison

        Would this work for you: explicitly assign the PanelDesigner as your MyBar class' designer through the DesignerAttribute attribute?

        <Designer("System.Web.UI.Design.WebControls.PanelDesigner")> _
        Public Class MyBar
        Inherits System.Web.UI.WebControls.Panel
        . . .
        End Class

        R Offline
        R Offline
        Richard Parsons
        wrote on last edited by
        #3

        Nope but I did find that if I specify the designer as System.Web.UI.Design.ControlDesigner the controls all show up the way they are suppose to, however I loose the ability to drag controls into my control. I found out that I could change my designer to ReadWriteControlDesigner but that makes it not draw the contorl correctly again... :( Learning new things is fun but aggravating at the same time. -Richard

        M 1 Reply Last reply
        0
        • R Richard Parsons

          Nope but I did find that if I specify the designer as System.Web.UI.Design.ControlDesigner the controls all show up the way they are suppose to, however I loose the ability to drag controls into my control. I found out that I could change my designer to ReadWriteControlDesigner but that makes it not draw the contorl correctly again... :( Learning new things is fun but aggravating at the same time. -Richard

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi Richard, As you superclass the Panel control, so if you use a designer for the control you either use the ReadWriteControlDesigner or a custom designer which inherits from the ReadWriteControlDesigner like PanelDesigner. At design time, you can drag/drop controls from the Toolbox onto your custom control, however, the control is not rendered properly in the design window because the GetDesignTimeHTML method is not called. If you use the ControlDesigner instead you can see the custom control displayed correctly as the GetDesignTimeHTML method is called, but you cannot drag/drop child controls any more. So there two things come to mind: + You don't programmatically add the label control in code, instead you can declare it in the ToolboxData attribute:

          [ToolboxData("<{0}:MyBar runat=server><asp:Label runat=server>Hello World</asp:Label></{0}:MyBar>")]
          public class MyBar : System.Web.UI.WebControls.Panel
          {
          ...
          }

          The downside of this way is clear when you want to add many child controls in your custom container control by default. + You may think of developing a template control.

          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