Nov 22, 2011, 6:39 AM
UserControls and Validation
Hello, I'm quite new here, I'm trying to play with ext.net.
My problem is with base page design.
Originally my idea was to use common html + UserControls + ext controls where it make sence
I found my first problem
validation does not work on the usercontrol
in fact, I was looking for something like https://examples1.ext.net/#/Layout/F..._UserControls/ where I wanted to mark Street as mandatory
The only solution I found was to introduce FormPanel into any usercontrol and somehow register all form on the page and validate one by one on submit... bit too crazy solution...
(in compare to simple usage of #{formId}.getForm().isValid() method or FormBind property
So am I right that using usercontrols is not the right idea when designing solutions using ext.net?
Whole purpose of excercise is follows: Our forms are quite complicated, we have usually form consited of 10-20 usercontrols, that are not here for reusing, but just to split the form into smaller pieces (units)
so what's the recomended approach for ext.net? From searching forums I got an impression that webcontrols.
Ok, that means no HTML, but thanks to the C# object/collection initializers, it's actually similar "syntax" like doing that in extjs (+ C# provieds intelisence)
That sounds good, I tried to create my first control, like this (just to encaspulate combobox)
So as a result -Am I right that for validating whole form, there must be single FormPanel on the page (so if there is nested form, the child forms are not validated when the parent is validated). In addition - is there anything like validation group?
is the Controls.Add, Items.Add used in correct way in right place?
a) is somewhere sample of whole website, where I can inspire
b)
The Name property is not rendered is the data to the page - so the data looks like
any idea why?
My problem is with base page design.
Originally my idea was to use common html + UserControls + ext controls where it make sence
I found my first problem
validation does not work on the usercontrol
in fact, I was looking for something like https://examples1.ext.net/#/Layout/F..._UserControls/ where I wanted to mark Street as mandatory
The only solution I found was to introduce FormPanel into any usercontrol and somehow register all form on the page and validate one by one on submit... bit too crazy solution...
(in compare to simple usage of #{formId}.getForm().isValid() method or FormBind property
So am I right that using usercontrols is not the right idea when designing solutions using ext.net?
Whole purpose of excercise is follows: Our forms are quite complicated, we have usually form consited of 10-20 usercontrols, that are not here for reusing, but just to split the form into smaller pieces (units)
so what's the recomended approach for ext.net? From searching forums I got an impression that webcontrols.
Ok, that means no HTML, but thanks to the C# object/collection initializers, it's actually similar "syntax" like doing that in extjs (+ C# provieds intelisence)
That sounds good, I tried to create my first control, like this (just to encaspulate combobox)
public class ComboBoxControl : Ext.Net.CompositeField
{
private ComboBox _combo;
private Store _store;
public ComboBoxControl()
{
_store = new Store
{
ID="ddlStore",
Reader =
{
new JsonReader
{
Fields =
{
new RecordField("Id"),
new RecordField("Name")
}
}
}
};
_combo = new ComboBox
{
//Store = {_store},
ID = "ddlCombo",
StoreID = "ddlStore",
DisplayField = "Name",
ValueField = "Id",
Mode = DataLoadMode.Local,
TriggerAction = TriggerAction.All,
EmptyText = "-- Select value --"
};
}
public bool AllowBlank
{
get { return _combo.AllowBlank; }
set { _combo.AllowBlank = value; }
}
protected override void OnInit(EventArgs e)
{
Controls.Add(_store);
Items.Add(_combo);
base.OnInit(e);
}
private void Bind(IEnumerable source)
{
List<object> data = new List<object>();
foreach (var item in source)
{
var property = item.GetType().GetProperty(item.GetType().Name.Replace("Class", "Name"));
object name = property.GetValue(item, null);
data.Add(new
{
Id = item.PrimaryKey.ToString(),
Name = name as string
});
}
_store.DataSource = data;
_store.DataBind();
}
}
It seems to work, but I'm not sure it's correct ( here I need an advice, as dozens of controls will be created in similar way)So as a result -Am I right that for validating whole form, there must be single FormPanel on the page (so if there is nested form, the child forms are not validated when the parent is validated). In addition - is there anything like validation group?
is the Controls.Add, Items.Add used in correct way in right place?
Controls.Add(_store);
Items.Add(_combo);
I have following partially related questionsa) is somewhere sample of whole website, where I can inspire
b)
data.Add(new
{
Id = item.PrimaryKey.ToString(),
Name = name as string
});
to data.Add(new
{
Id = item.PrimaryKey.ToString(),
Name = name
});
(name is of object type)The Name property is not rendered is the data to the page - so the data looks like
this.ctl00_ctl00_cphPageContent_cphPageContent_ddlStore = new Ext.ux.data.PagingStore({proxyId:"ctl00_ctl00_cphPageContent_cphPageContent_ddlStore",autoLoad:true,reader:new Ext.data.JsonReader({fields:[
{name:"Id"},
{name:"Name"}
]}),directEventConfig:{},
proxy:new Ext.data.PagingMemoryProxy([
{"Id":"9000579"},
{"Id":"9000520"},
{"Id":"9000553"},
{"Id":"9000609"},
{"Id":"9000552"},
......any idea why?
Last edited by geoffrey.mcgill; Nov 22, 2011 at 7:45 AM.
Reason: please use [CODE] tags