Custom Controls
-
Hi, I'm building a customer control. Which I want to have another custom control in it. So I declare the tag like: <cc:Control1 runat="server" id="control1"> <Control2 runat="server" Width="100px"> <cc:Control2Item Text="Do This"/> <cc:Control2Item Text="Do That"/> </Control2> <Columns> ... </Columns> </cc:Control1> Control1 has a property called Control2 which is of type Control2 Though this doesn't render the Control2 html. What do I need to do to have the parent control render the child? Is there a good article somewhere? I have looked a little but still no luck. I have tried things with [ParseChildren(true, "Control2")] in the Control1 code, but then this gives errors and the Control2Item types. Really not sure what i'm doing wrong, kinda new to custom controls. Thanks for any info. Luke
-
Hi, I'm building a customer control. Which I want to have another custom control in it. So I declare the tag like: <cc:Control1 runat="server" id="control1"> <Control2 runat="server" Width="100px"> <cc:Control2Item Text="Do This"/> <cc:Control2Item Text="Do That"/> </Control2> <Columns> ... </Columns> </cc:Control1> Control1 has a property called Control2 which is of type Control2 Though this doesn't render the Control2 html. What do I need to do to have the parent control render the child? Is there a good article somewhere? I have looked a little but still no luck. I have tried things with [ParseChildren(true, "Control2")] in the Control1 code, but then this gives errors and the Control2Item types. Really not sure what i'm doing wrong, kinda new to custom controls. Thanks for any info. Luke
Ok I can now get the child control rendering, I had to call it's RenderControl... Pretty simple. My issue is now that Control1 inherites from a DataGrid and I want to add a column everytime to the end. I was doing this in the OnInit() method and it was working. until now, because the new column need a reference to the controllist of Control2 which has not been created yet. So if I move the code to OnPrerender, or Render the code does not fial because the Control2 controls has been created, but so have the Control1 controls so the new column does not show up. Any ideas?
-
Hi, I'm building a customer control. Which I want to have another custom control in it. So I declare the tag like: <cc:Control1 runat="server" id="control1"> <Control2 runat="server" Width="100px"> <cc:Control2Item Text="Do This"/> <cc:Control2Item Text="Do That"/> </Control2> <Columns> ... </Columns> </cc:Control1> Control1 has a property called Control2 which is of type Control2 Though this doesn't render the Control2 html. What do I need to do to have the parent control render the child? Is there a good article somewhere? I have looked a little but still no luck. I have tried things with [ParseChildren(true, "Control2")] in the Control1 code, but then this gives errors and the Control2Item types. Really not sure what i'm doing wrong, kinda new to custom controls. Thanks for any info. Luke
Hi there, You might want to check out some good articles in MSDN to see how to develop a templated custom control: Building Templated Custom ASP.NET Server Controls[^] Building DataBound Templated Custom ASP.NET Server Controls[^] Developing ASP.NET Server Controls[^] If you want to look for a book, I recommend this one: Developing Microsoft® ASP.NET Server Controls and Components [^]