PDA

View Full Version : [CLOSED] How to write a datetime composite control which combine DateField and TimeField control



wangyi
Sep 03, 2013, 8:49 AM
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.Cellpa dding,"0");
writer.AddAttribute(HtmlTextWriterAttribute.Cellsp acing, "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>

Daniil
Sep 03, 2013, 1:49 PM
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.

wangyi
Sep 04, 2013, 2:38 AM
Can you give a code sample? help!

Daniil
Sep 04, 2013, 6:05 AM
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>

wangyi
Sep 04, 2013, 7:27 AM
Thanks for your solution. It helped me.