问题描述
我的应用程序在带有C#的ASP.NET 2.0中.我有一个带有正则表达式 ^ [0-9] *(\\,)?[0-9]?[0-9]?$
的正则表达式验证器,现在我的客户端没有希望在客户端进行此验证,但在按钮上单击即服务器端.
My application is in ASP.NET 2.0 with C#. I have a regular expression validator with the regular expression ^[0-9]*(\\,)?[0-9]?[0-9]?$
, now my client don't want this validation at client side but on button click i.e. Server Side.
EX:我必须检查 txtPrice
文本框的值
EX: I have to check the value of txtPrice
textbox
请让我知道如何将该正则表达式验证放在服务器端.
Please let me know how can I put this regular expression validation on server side.
提前谢谢.
推荐答案
您可以使用CustomValidator,它可以链接到服务器端事件:
You can use a CustomValidator which can link to a server side event:
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" OnServerValidate="CustomValidator1_Validate"></asp:CustomValidator>
然后您可以在服务器端验证输入
Then server side you can validate input
protected void CustomValidator1_Validate (object source, ServerValidateEventArgs argss)
{}
请记住,用
if(IsValid) {}
确保所有验证者都受到尊重
To ensure all validators are respected
这篇关于ASP.NET 2.0中的服务器端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!