[CLOSED] How to write a datetime composite control which combine DateField and TimeField control

  1. #1

    [CLOSED] How to write a datetime composite control which combine DateField and TimeField control

    I need a datetime composite control. I want to combine DateField control and TimeField control.
    In ASP.NET , I know how to write the code as follow's code.

    public class CustomDateTime :  System.Web.UI.WebControls.CompositeControl  
    {
        DateField ctrdate = new DateField();
        TimeField ctrtime = new TimeField();
    }
    
    
      protected override void CreateChildControls()
            {
                Controls.Clear();
    
                Controls.Add(ctrdate);
                Controls.Add(ctrtime);
    
                ChildControlsCreated = true;
            }
    
    
       protected override void RenderContents(HtmlTextWriter writer)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,"0");
                writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                writer.RenderBeginTag(HtmlTextWriterTag.Table);
    
                
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                ctrdate.RenderControl(writer);
                writer.RenderEndTag();
    
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                ctrtime.RenderControl(writer);
                writer.RenderEndTag();
    
                writer.RenderEndTag();
                writer.RenderEndTag();
            }
        }
    But the CustomDateTime control only can be inside html table remak. It can not be inside ext:panel's items remark.
    But I want to use ext.net's layout, I need the CustomDateTime control inside ext:panel's items remark.

    How can I write the datetime composite control in Ext.net ? It can use as follows:
                          <ext:Panel ID="PanelResult" runat="server"  >
                                <Items>
                                     <MyControl:CustomDateTime ID="CustomDateTime1" runat="server" ></MyControl:CustomDateTime>
                                </Items>
                            </ext:Panel>
    Last edited by Daniil; Sep 04, 2013 at 12:01 PM. Reason: [CLOSED]
  2. #2
    Hi @wangyi,

    You can derive from the Ext.Net.FieldContainer class putting both a DateField and a TimeField there.

    Seems there was an example of the forums, but I cannot find it.
  3. #3

    Can you give a code sample? help!

    Can you give a code sample? help!
  4. #4
    Here you are.
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        public class MyDateTimeField : FieldContainer
        {
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                this.Layout = "hbox";
                this.Width = 300;
                this.Items.Add(new DateField() { Flex = 1 });
                this.Items.Add(new TimeField() { Flex = 1 });
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Panel1.Items.Add(new MyDateTimeField());
            }
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Panel ID="Panel1" runat="server" />
        </form>
    </body>
    </html>
  5. #5

    Thanks

    Thanks for your solution. It helped me.

Similar Threads

  1. Replies: 1
    Last Post: Apr 19, 2012, 12:35 PM
  2. Replies: 11
    Last Post: Mar 08, 2012, 2:27 AM
  3. [CLOSED] Create web server control (composite control)
    By mmmartins in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: May 13, 2011, 6:18 PM
  4. [CLOSED] Styling Composite Control
    By jthompson in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 01, 2011, 9:18 AM
  5. [CLOSED] [1.0] Help with composite control
    By russ in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 16, 2011, 10:16 AM

Tags for this Thread

Posting Permissions