选择性验证? [英] Selective validation?
问题描述
我正在开发一个显示新闻通讯的Webform.在新闻通讯的底部,有一个注释文本框,允许用户发表评论.我在评论框上附加了RequiredFieldValidator,以防止发布空评论.
一切正常,但我尝试添加注册"功能,以便用户可以在其收件箱中注册其电子邮件地址以接收新闻.
注册"功能包括:
* txtEmailAddress,
* txtEmailAddress
的RequiredFieldValidator * btnSignUp
现在,当单击btnSignUp时,txtComments的RequiredFieldValidator将不允许页面回发!
我知道一个简单的解决方案是将用户重定向到另一个页面进行注册,并将btnSignUp属性设置为:CauseValidation为false.我想我太牛逼了,但我想让用户快速访问新闻页面上的注册!谢谢,除了
Richard
I''m developing a Webform that displays a newsletter. At the bottom the newsletter, there is a comment textbox to allow the user to post a comment. I have a RequiredFieldValidator attached to the comment box to prevent empty comments from being posted.
All is working fine but I''m trying to add a "Sign Up" function so the user can register their e-mail address to receive the newsletter in their inbox.
The "Sign Up" functionality consists of:
* txtEmailAddress,
* RequiredFieldValidator for txtEmailAddress
* btnSignUp
Now when btnSignUp is clicked, the RequiredFieldValidator for txtComments will not allow the page to postback!
I know an easy solution would be to redirect the user to another page for registering and set btnSignUp property: CauseValidation to false. I guess I''m too bull headed but I want to give the user the quick access of signing up on the newsletter page! Is there any way besides a lot of javascript to accomplish this?
Thanks,
Richard
推荐答案
设置验证组,以便注册字段不会触发对注释字段的验证
http: //msdn.microsoft.com/zh-CN/library/ms227424.aspx [
You can set the validation group so the signup fields don''t trigger the validation for the comment field
http://msdn.microsoft.com/en-us/library/ms227424.aspx[^]
注册"功能包括:
* txtEmailAddress,
* txtEmailAddress的RequiredFieldValidator
* btnSignUp
现在,当单击btnSignUp时,txtComments的RequiredFieldValidator将不允许页面回发!
The "Sign Up" functionality consists of:
* txtEmailAddress,
* RequiredFieldValidator for txtEmailAddress
* btnSignUp
Now when btnSignUp is clicked, the RequiredFieldValidator for txtComments will not allow the page to postback!
您需要为其创建ValidationGroup
. txtEmailAddress,txtEmailAddress和btnSignUp的RequiredFieldValidator应该在同一验证组下. :-D
You need to create the ValidationGroup
for it. RequiredFieldValidator for txtEmailAddress , txtEmailAddress and btnSignUp should be under same validation group. :-D
这篇关于选择性验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!