Sure, this is a small example.
I would, get variable's value "value", in C#.
I know that I would use DirectEvent Change but, I prefer set when I need it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using System.Xml.Serialization;
using Ext.Net;
using Container = Ext.Net.Container;
using Newtonsoft.Json;
[assembly: WebResource("ExtNetTestEnv.UI.AnyControl.AnyControl.js", "text/javascript")]
namespace ExtNetTestEnv.UI
{
public enum ControlKind
{
TextField,
DataField
}
public class AnyControl : Container
{
public ControlKind Kind
{
get { return State.Get("kind", ControlKind.TextField); }
set { State.Set("kind", value); }
}
public string Value
{
get
{
Call("getValue");
return State.Get("value", "");
}
set { State.Set("value", value); }
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[XmlIgnore]
[JsonIgnore]
public override ConfigOptionsCollection ConfigOptions
{
get
{
ConfigOptionsCollection list = base.ConfigOptions;
list.Add("kind", new ConfigOption("kind", new SerializationOptions("kind", JsonMode.Value),
ControlKind.TextField, Kind));
list.Add("value", new ConfigOption("value", new SerializationOptions("value", JsonMode.Value),
"", Value));
return list;
}
}
[Category("0. About")]
[Description("")]
public override string InstanceOf
{
get { return "App.AnyControl"; }
}
[Category("0. About")]
[Description("")]
public override string XType
{
get { return "anycontrol"; }
}
protected override List<ResourceItem> Resources
{
get
{
List<ResourceItem> baseList = base.Resources;
baseList.Capacity += 1;
baseList.Add(new ClientScriptItem(typeof(AnyControl),
"ExtNetTestEnv.UI.AnyControl.AnyControl.js", ""));
return baseList;
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
DirectEvents.AfterRender.Event += (caller, args) =>
{
if (Kind == ControlKind.TextField)
{
new TextField
{
ID = "text",
FieldLabel = "Text"
}.Render(this);
}
else
{
new DateField
{
ID = "date",
FieldLabel = "Text"
}.Render(this);
}
};
}
}
}
Ext.define('App.AnyControl', {
extend: 'Ext.container.Container',
alias: 'widget.anycontrol',
kind: 'TextField',
value: '',
getValue: function () {
var item = this;
if (item.kind == 'TextField') {
var txt = item.down('textfield');
if (txt) {
item.value = txt.getValue();
}
} else {
var dt = item.down('datefield');
if (dt) {
item.value = dt.getValue();
}
}
return item.value;
}
});
I hope I was clear