在 C# 中使用按钮事件进行转发器文本框验证
我有这个中继器,我在文本框中添加了一些验证。但是,我希望用来触发验证的按钮位于转发器之外。这可能吗?如果是这样,我宁愿使用服务器端。
<asp:Repeater ID="rptCart" runat="server" onitemcommand="Cart_ItemCommand" onitemdatabound="Cart_ItemDataBound">
<ItemTemplate>
<asp:TextBox ID="cartQty" runat="server" Text='<%#Eval("shoppingCartQty")%>'></asp:TextBox></span>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="oops!" ControlToValidate="cartQty" CssClass="errortxt" Display="Dynamic"></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="oops!" ValidationExpression="^[0-9]*[1-9]+[0-9]*$" CssClass="errortxt" ControlToValidate="cartQty" Display="Dynamic"></asp:RegularExpressionValidator></span>
</ItemTemplate>
</asp:Repeater>
<asp:LinkButton ID="cartRecalcButton" CssClass="cartrecalcbutton"
runat="server" ToolTip="recalculate your shopping cart"
onclick="cartRecalcButton_Click">
</asp:LinkButton>
I have this repeater where i have added some validation to a textbox. However, the button I wish to use to fire the validation is outside the repeater. Is this possible? If so, I'd rather use server side.
<asp:Repeater ID="rptCart" runat="server" onitemcommand="Cart_ItemCommand" onitemdatabound="Cart_ItemDataBound">
<ItemTemplate>
<asp:TextBox ID="cartQty" runat="server" Text='<%#Eval("shoppingCartQty")%>'></asp:TextBox></span>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="oops!" ControlToValidate="cartQty" CssClass="errortxt" Display="Dynamic"></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="oops!" ValidationExpression="^[0-9]*[1-9]+[0-9]*$" CssClass="errortxt" ControlToValidate="cartQty" Display="Dynamic"></asp:RegularExpressionValidator></span>
</ItemTemplate>
</asp:Repeater>
<asp:LinkButton ID="cartRecalcButton" CssClass="cartrecalcbutton"
runat="server" ToolTip="recalculate your shopping cart"
onclick="cartRecalcButton_Click">
</asp:LinkButton>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,你可以。如果您不希望进行客户端验证,可以设置 BaseValidator.EnableClientScript 属性设置为 false。验证控件始终在服务器上执行验证。
Yes you can. If you don't want the clientside validation to happen you can set the BaseValidator.EnableClientScript property to false. Validaton controls always performs validation on the server.
使用中继器外部的按钮来验证中继器中的数据应该不会有任何问题。如果您想将验证范围限制为转发器,您可以使用
ValidationGroup
。You shouldn't have any problems using a button outside of the repeater to validate data in the repeater. You can use a
ValidationGroup
if you want to limit the scope of the validation to the repeater.