locked
Custom Templated Control RRS feed

  • Question

  • User1605460476 posted

    I'm attempting to build a hybrid of the DetailsView control (multi-column).  We do alot of data entry webforms, and I'm hoping to speed the process up a bit.  I'd like my markup to look similar to the following

            <cc1:MyForm ID="DataEntryForm1" runat="server" Columns="2">
                <ViewTemplate>
                    <cc1:Field Question="What is your name?">
                        <asp:Label ID="myLabel" runat="server" />     
                    </cc1:Field>
                    <cc1:Field Question="What is your height?">
                        <asp:TextBox ID="myTextbox" runat="server" />
                    </cc1:Field>
                </ViewTemplate>
            </cc1:MyForm>

    I can't figure out how to get the Field control to accept child controls in it's markup, without inheriting from WebControl.  Can anyone provide some help?  I've also included the skeleton of my code below.

        public class MyForm : WebControl, INamingContainer
        {
            private DataEntryControlCollection _view;
    
            [PersistenceMode(PersistenceMode.InnerProperty)]
            public DataEntryControlCollection ViewTemplate
            {
                get
                {
                    if (_view == null)
                    {
                        _view = new DataEntryControlCollection();
                    }
                    return _view;
                }
            }
        }
    
        public class DataEntryControlCollection : CollectionBase
        {
            ...
        }
    
        [ParseChildren(false)]
        public class Field
        {
            private string _question;
    
            public string Question
            {
                get { return _question; }
                set { _question = value; }
            }
    
        }



     


     

    Monday, August 17, 2009 11:47 AM

All replies

  • User1605460476 posted
    I've pretty much got it working by adding a 'FieldControls' property to he Field control.  I'd like to remove the 'FieldControls' element.  Suggestions?
           <cc1:MyForm ID="DataEntryForm1" runat="server">
                <ViewTemplate>
                    <cc1:Field Question="What is your name?">
                        <FieldControls>
                            <asp:Textbox ID="txtName" runat="server" />     
                        </FieldControls>
                    </cc1:Field>
                    <cc1:Field Question="What is your height?">
                        <FieldControls>
                            <asp:TextBox ID="txtHeight" runat="server" />
                        </FieldControls>
                    </cc1:Field>
                </ViewTemplate>
            </cc1:MyForm>

        [ParseChildren(true, "FieldControls")]
        public class Field
        {
            private string _question;
            private ITemplate _fieldControls;

            public string Question
            {
                get { return _question; }
                set { _question = value; }
            }

            [PersistenceMode(PersistenceMode.InnerDefaultProperty),
            TemplateContainer(typeof(FieldContainer))]
            public ITemplate FieldControls
            {
                get
                {
                    return _fieldControls;
                }
                set
                {
                    _fieldControls = value;
                }

            }

        }

        public class FieldContainer : INamingContainer {}


     


    Monday, August 17, 2009 3:20 PM
  • User1605460476 posted
    I've pretty much got it working by adding a 'FieldControls' property to the Field control.  I'd like to remove the 'FieldControls' element.  Suggestions?
           <cc1:MyForm ID="DataEntryForm1" runat="server">
                <ViewTemplate>
                    <cc1:Field Question="What is your name?">
                        <FieldControls>
                            <asp:Textbox ID="txtName" runat="server" />     
                        </FieldControls>
                    </cc1:Field>
                    <cc1:Field Question="What is your height?">
                        <FieldControls>
                            <asp:TextBox ID="txtHeight" runat="server" />
                        </FieldControls>
                    </cc1:Field>
                </ViewTemplate>
            </cc1:MyForm>
        [ParseChildren(true, "FieldControls")]
        public class Field
        {
            private string _question;
            private ITemplate _fieldControls;
    
            public string Question
            {
                get { return _question; }
                set { _question = value; }
            }
    
            [PersistenceMode(PersistenceMode.InnerDefaultProperty),
            TemplateContainer(typeof(FieldContainer))]
            public ITemplate FieldControls
            {
                get
                {
                    return _fieldControls;
                }
                set
                {
                    _fieldControls = value;
                }
    
            }
        }
    
        public class FieldContainer : INamingContainer {}


     


     


    Monday, August 17, 2009 3:20 PM