2014年7月13日 星期日

[RESOLVED] Is it possible to validate 2 controls with 1 validator


Say, I actually want 1 required field validator and 2 radiolist controls.and i have a selection option there where i want either radiolist1 or radiolist2 to be validated not selecting neither radio1 or radio2 will give error.Is it Possible?


If this is not possible then I have to use a textbox to validate all these..



i think not possible that is what i need to say as is. reason the control id is one that bind with a validator control. yes contrary to is radolist


validation in this could be off comparevalidator.









Hi anirudh_4sag,


I think for such validation which are not possible to be implemented directly by built-in server controls, you should use CustomValidator. and in server side Validate event of this Validator, you can write custom code to put your custom validation code.



Hi,


One suggestion is you can change the controltovalidate attribute of validator on code behind based on the situation.


eg:


if(conditon)


{


validator1.controltovalidate=ID of control1;


}


else


{


validator1.controltovalidate=ID of control2;


}


Thanks,


Saritha.



The built in validator controls (such as RequiredField etc) all act on a single control (apart from the Comapre one, obviously).  If you need validator controls that act on multiple controls based on custom logic then you have to use a custom validator. 
Google for the exact syntax but it's quite straight-forward.  You just specify the method you want to use when the control is asked to validate, you do your work and specify true or false for if the validation worked.  If you want to support client-side validation
there is similarly a property that lets you specify the name of a javascript function to call.


沒有留言:

張貼留言