locked
Create custom server control with nested templates RRS feed

  • Question

  • User359835732 posted

    I want to make a custom templated server control that supports the following:

    <cc:NestedTemplates ID="_nestedTemplates" runat="server">

    <Template1></Template1>

    <Template2></Template2>

    <Template3></Template3>

    <Template4></Template4>

    <MasterTemplate>

        <table>

         <tr><td><Template1><Template5><td>data from DataTable</td></Template5></Template1></td>

              <td><Template2><Template6><td>data from DataTable</td></Template6></Template2></td>

         </tr>

        <tr>

            <td><Template3><Template7><td>data from DataTable</td></Template7></Template3></td>

            <td><Template4><Template8><td>data from DataTable</td></Template8></Template4></td>

        </tr>

    </table>

    </cc:NestedTemplates>

    Where Templates 5 through 6 would be blown into HTML tables themselves.

    Is it possible to create such a control?  Any examples anywhere of how to do this?

    Friday, October 19, 2012 9:17 PM

All replies

  • User359835732 posted

    A follow up question:

    Is there a way I can read the markup within the Templates in my custom templated server control into a string variable?  Trying to access the markup but don't know how to do so...

    Friday, October 19, 2012 9:21 PM
  • User3866881 posted

    Is it possible to create such a control?  

    I think the problem should be done through inherting the class "DataBoundControl". You can see this sample,you can learn how to do the Bound fields from the given father class and do what you like:

    http://www.codeproject.com/Articles/344095/Creationism-Custom-Data-Bound-Controls-for-ASP-NET

    Sunday, October 21, 2012 7:36 PM
  • User359835732 posted

    I don't think creating a custom DataBoundControl will help, as we want to be able to change the look and feel for individual cells based on templates.

    Monday, October 22, 2012 2:07 PM
  • User3866881 posted

    I don't think creating a custom DataBoundControl will help, as we want to be able to change the look and feel for individual cells based on templates.

    But considering it that you wanna fetch data contents from db, maybe you need to bind a DataSource to your control. I hope DataBoundControl will help you;)

    Monday, October 22, 2012 10:07 PM