Last post Feb 29, 2008 11:14 AM by pbz
Feb 28, 2008 09:28 AM|Edgars.Cizevskis|LINK
I'm now studying how to crate custom designers for custom web controls ... and i had some problems here i cant get rid and wast able to find solutions yet.
For example i have WebControl with Control Collection property and i would like to show them in designer exactly like its in Run-time (just show with no edit). And in designer i do generate Panel and adding all child controls from my property to that panel
... and panel to Component of designer.
If I add random controls like Buttons, TextBoxes, Link and others they all are seen in designer like i whanted ... but if i add there UserControl (Registered in page code - not .cs file dynamic load) then it not showing. Why is that and/ or
what can i do to see it like other simple controls???
Feb 28, 2008 10:30 AM|pbz|LINK
Are you trying to add your control to a panel and it doesn't show up, or your control is a container and you drop buttons, text boxes, etc. in it? It would be helpful to see some of your code or at least describe in detail what it showing in the designer
and what you would like to see.
Feb 28, 2008 11:05 AM|Edgars.Cizevskis|LINK
<cc1:MyCustomControl ID="MyCustomControl1" runat="server">
<uc2:WebUserControl2 ID="WebUserControl1" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:LinkButton ID="LinkButton2" runat="server">LinkButton</asp:LinkButton>
My designer inherits ControlDesigner and on GetDesignTimeHtml() i generate Panel, adding it to Designer Component (MyCustomControl) and in panel i add every child control from CustomControlCollection and everything exept WebUserControl is displayed
Feb 28, 2008 12:00 PM|pbz|LINK
Have you tried PanelContainerDesigner instead? I have a custom control where the designer inherits from this class and I can see user controls inside just fine. However, I'm not using a collection but instead allow those controls to be the children of MyCustomControl
(in your case). Getting the designer to work is one area where VS is a @!#!$ to work with :)
Feb 29, 2008 10:56 AM|Edgars.Cizevskis|LINK
PanelContainerDesigner is made for Panel class or any other who inherit it ... so if my control is no panel i got "Error Creating Control: Value must be of type 'System.Web.UI.WebControls.Panel. Parameter name: component" ... and still it should be EditableDesignerRegion
I did reduced ContainerControlDesigner in my inherited designer to not show header and dont apply its own styles and in override SetEditableDesignerRegionContent() i commented base class function ... so i got area like panel with editable content containing
all UserControls and it doesnt change ASP code and just refresh to default ... but thats not really im interested in to know. These editable regions some how loading content of any control and it is shown (maybe using something like ControlPersister) and that's
what i wish to know if someone have such knowlage and could share. Because i just trying to learn what Designer can do and what can i do with it! :) But thanks for feedback.
Feb 29, 2008 11:14 AM|pbz|LINK
For some reason I was under the impression that you were inheriting from Panel, sorry. I'd recommend you download the source for the AjaxControlToolkit (or any other control that you have access to) and look at how it's done there. From my experience, when
it comes to designer support, you'll learn more by looking at code than trying to search tutorials online. A good book about writing custom controls is this one
http://www.amazon.com/Developing-Microsoft-ASP-NET-Controls-Components/dp/0735615829, but unfortunately is a bit outdated since it was written for 1.1; nevertheless a lot of it still applies.