[英]OnItemCommand of asp:Repeater not working with validator
the function in OnItemCommand
of the asp:Repeater
is not working randomly. asp:Repeater
OnItemCommand
中的函数不是随机工作的。 It's a normal one coded like this. 这是一个正常的编码。
<asp:Repeater runat="server" ID="control01" OnItemCommand="control01_OnItemCommand">
<ItemTemplate>
<li><asp:LinkButton runat="server" ID="btn_button" CommandArgument='1'>Click</asp:LinkButton></li>
</ItemTemplate>
</asp:Repeater>
After some time spent on debug I found it's related a input text box on page. 花了一些时间在调试上,我发现它与页面上的输入文本框相关。
<asp:TextBox ID="txt_input" runat="server"></asp:TextBox>
Only if it's correct value (validated) the function works well. 只有当它的值正确(有效)时,该功能才能正常工作。
If I remove <asp:RequiredFieldValidator>
and <asp:RequiredFieldValidator>
on the text box here 如果我在这里的文本框中删除
<asp:RequiredFieldValidator>
和<asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rvDecimal" ControlToValidate="txt_input" runat="server" ErrorMessage="Please enter a valid value" ValidationExpression="^(-)?\d+(\.\d\d)?$"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="rfd_input" runat="server" ControlToValidate="txt_input" Text="Please enter a valid value"></asp:RequiredFieldValidator>
OnItemCommand
got fired and the function works well. OnItemCommand
被解雇了,该功能运行良好。
The question is, how can I keep the validation and make the function in OnItemCommand
working? 问题是,如何保持验证并使
OnItemCommand
的功能正常工作?
If you want the postback to occur even when a validation fails, you can disable the client validation: 如果您希望即使验证失败也会发生回发,您可以禁用客户端验证:
<asp:RegularExpressionValidator ID="rvDecimal" runat="server" EnableClientScript="false" ... />
<asp:RequiredFieldValidator ID="rfd_input" runat="server" EnableClientScript="false" ... />
If you want to see an indicator besides each field, showing that its data is not valid, then the validators should have a Text
property. 如果要查看每个字段旁边的指示符,表明其数据无效,则验证程序应具有
Text
属性。
On the other hand, if you want a list of failed validations, you can add a ValidationSummary to the page and an ErrorMessage
to each validator. 另一方面,如果需要失败的验证列表,可以向页面添加ValidationSummary,并为每个验证器添加
ErrorMessage
。
Finally I've solved the problem by adding CausesValidation="false"
in the control. 最后,我通过在控件中添加
CausesValidation="false"
来解决问题。
<asp:LinkButton runat="server" ID="btn_button" CausesValidation="false">
This would skip the validation the trigger the function in OnItemCommand
这将跳过验证触发
OnItemCommand
的函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.