尽管我确实注意到了一些问题,但您在这里所拥有的一切都很好。
- .LabelAlign 属性必须在容器级别设置。Container 也必须使用 FormLayout。不幸的是 .LabelAlign 不能在字段级别以不同的方式呈现。
- 实际上并不需要将 .FieldLabel 属性设置为“CPF”,除非您预计所有这些“CpfField”组件都被标记为“CPF”。.FieldLabel 通常在字段配置级别设置,在实例化字段时在标记或代码隐藏中设置。
您可以调查的另一个“全局”选项是使用 .skin 文件。下面的示例通过“全局”设置所有 TextField 组件的属性来演示此选项。
下面的示例演示了几个选项,包括在对象的 OnInit 事件中设置属性。
示例 (.skin)
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
<ext:TextField runat="server" Icon="Accept" />
示例 (.aspx)
<%@ Page Language="C#" Theme="Skin1" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
var form = new FormPanel
{
Height = 215,
Width = 350,
Title = "Example",
Padding = 5,
DefaultAnchor = "100%",
Items = {
new MyField
{
FieldLabel = "My Field"
},
new AnotherField
{
FieldLabel = "Another Field"
},
new TextField
{
FieldLabel = "A TextField"
}
}
};
this.Form.Controls.Add(form);
}
public class MyField : TextField
{
public MyField()
{
this.SelectOnFocus = true;
this.AllowBlank = false;
this.MaxLength = 14;
}
}
public class AnotherField : TextField
{
protected override void OnInit(EventArgs e)
{
this.SelectOnFocus = true;
this.AllowBlank = false;
this.MaxLength = 14;
base.OnInit(e);
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
</form>
</body>
</html>
希望这可以帮助。