Wiki
This website is a wiki. If you like and use our processes, techniques and tools, please add your experience and best practices. Just register and share.


Contents


User


Smart


Community

















Sometimes a default generated panel is just not enough. You need to set specific properties, or want to use a special control. But you don't want to loose the easy binding features of the BindManager. You can still use standard binding, but you have to know how the BindManager works. Key is naming the controls correctly.

The BindManager uses a specific binder class for every type of control. There is a TextBoxBinder for a TextBox and a DropDownListBinder for a DropDownList, etc. When these binders are registered to the BindManager (ofcourse using DI) they indicate which type of control they can bind. This is done by prefixes like 'txt' and 'ddl'.

When binding a DomainObject all the instance properties of the entity are listed and for every property a set of combinations they the prefix keys are generated. The control to which you are binding is then search for all these combinations. The format used is:
<key><type of DomainObject><name of property>

So if an entity User has a property Name which should be represented in a TextBox, the control should have the name txtUserName.

In the default generated panel the control is generated as:
public partial class PanelUser : SmartPanel
{
	protected override void OnInit(EventArgs e)
	{
		Add(ValidatedTextBoxItem.Create("Name", "UserName", 50, Editable, true));

As name is passed "UserName". The SmartPanel will generate the appropriate prefix for it, in this case "txt".

Custom controls

So, how to add your own control? There are two ways:
  • Create a PanelItem for it and just use it directly in your existing panel. The advantage is it will be integrated in the layout of the other controls and maintains the consistency of your code.
  • Create your own control and add it manually to the form. In that case you have to make sure you name it correctly so it's possible to use the BindManager.

Here is an overview of default web binders and which prefixes they use.
BinderKeys
CheckBoxBindercbx
DataGridBindergrd
DateTimeBinderdtb, cal
DropDownListBinderddl
GridViewBindergrd
HyperLinkBinderhl
LabelBinderlbl
RadioButtonListBinderrbl
TextBoxBindertxt

For windows there are the following binders:
BinderKeys
CheckBoxBindercbx
DateTimeBinderdtp, cal
DropDownListBinderddl
GridViewBindergrd
LabelBinderlbl
MaskedTextBoxBindermsk
RadioButtonListBinderrbl
TextBoxBindertxt

If you cannot use one of above binders for your special control, you can create your own binder by just implementing the IControlBinder interface. Register it by adding it to the application config file.