[英]Class Attributes (?) in ASP.NET Web Form Page
I have created a custom BoundField class in C#. 我在C#中创建了一个自定义的BoundField类。 I have added ASP.NET validators to the TextBox and exposed the TextBox OnTextChanged event in Edit and Insert modes.
我在TextBox中添加了ASP.NET验证器,并在编辑和插入模式下公开了TextBox OnTextChanged事件。 I am experiencing an annoyance with the validators though.
我遇到了验证者的烦恼。
I have exposed the validators publicly like in this example: 我在这个例子中公开公开了验证器:
private RequiredFieldValidator _requiredFieldValidator;
public RequiredFieldValidator RequiredFieldValidator
{
get { return _requiredFieldValidator ?? (_requiredFieldValidator = new RequiredFieldValidator()); }
}
I have used this approach to avoid having to set up countless custom public properties in the control itself. 我已经使用这种方法来避免在控件本身中设置无数的自定义公共属性。 I can now do this...
我现在可以做到这一点......
<cc1:BoundFieldWithTextChangedEvent DataField="size2" HeaderText="Width" SortExpression="size2" ItemStyle-CssClass="numeric" OnTextChanged="size2_OnTextChanged" AutoPostBack="True"
RequiredFieldValidator-Text="!"
RequiredFieldValidator-Display="Dynamic" />
This code compiles fine and the validations work properly on the page; 此代码编译良好,验证在页面上正常工作; but I am seeing squiggles under the "RequiredFieldValidator-Text" and "RequiredFieldValidator-Display" attributes in Visual Studio 2013. The first warning is:
但我在Visual Studio 2013中的“RequiredFieldValidator-Text”和“RequiredFieldValidator-Display”属性下看到了波形。第一个警告是:
Validation (ASP.Net): Attribute 'RequiredFieldValidator-Text' is not a valid attribute of element 'BoundFieldWithTextChangedEvent'.
验证(ASP.Net):属性'RequiredFieldValidator-Text'不是元素'BoundFieldWithTextChangedEvent'的有效属性。
The other warnings are for the rest of the "RequiredFieldValidator-" attributes. 其他警告是针对“RequiredFieldValidator-”属性的其余部分。
What do I need to do my custom control code to make these attributes behave properly with Visual Studio 2013? 使用Visual Studio 2013,我需要执行哪些自定义控件代码才能使这些属性正常运行?
EDIT: Thanks to Alex Lebedev's help below, my problem has been solved. 编辑:感谢Alex Lebedev的帮助,我的问题已经解决了。
I needed to do two things: 我需要做两件事:
[PersistenceMode(PersistenceMode.InnerProperty)]
above my public validator properties in my custom control. [PersistenceMode(PersistenceMode.InnerProperty)]
。 <cc1:BoundFieldWithTextChangedEvent DataField="size2" HeaderText="Width" SortExpression="size2" ItemStyle-CssClass="numeric" OnTextChanged="size2_OnTextChanged" AutoPostBack="True" ItemStyle-Wrap="false" ValidationGroup="UpdateItem"> <RequiredFieldValidator Text="!" ErrorMessage="You must specify a width." Display="Dynamic" SetFocusOnError="true" EnableClientScript="true"></RequiredFieldValidator> <CompareValidator Text="*" ErrorMessage="Width must be greater than zero." Operator="GreaterThan" ValueToCompare="0" Type="Double" Display="Dynamic" SetFocusOnError="true" EnableClientScript="true"></CompareValidator> </cc1:BoundFieldWithTextChangedEvent>
<cc1:BoundFieldWithTextChangedEvent DataField="size2" HeaderText="Width" SortExpression="size2" ItemStyle-CssClass="numeric" OnTextChanged="size2_OnTextChanged" AutoPostBack="True"
RequiredFieldValidator-Text="!"
RequiredFieldValidator-Display="Dynamic" />
Replace it with: 替换为:
<cc1:BoundFieldWithTextChangedEvent DataField="size2" HeaderText="Width" SortExpression="size2" ItemStyle-CssClass="numeric" OnTextChanged="size2_OnTextChanged" AutoPostBack="True">
<RequiredFieldValidator Text="!" Display="Dynamic"/>
</cc1:BoundFieldWithTextChangedEvent>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.