I need to place some validation on an asp button to ensure it is clicked at least once.
I setup a Custom Validator, set controlToValidate as the button but then found out the Custom Validator can only validate certain controls and a button isn’t one of them.
I thought about validating an invisible textbox directly next to the button but this didn’t feel right. Is creating dummy controls for this sort of thing ok? Or is it bad practice? Any advice?
Thanks
I will stay away from creating dummy controls. Let me ask you, why do you need to validate this? why does the user has to click on a button at least once? maybe you are using the wrong control for this, without knowing what you are trying to accomplish, I still want to suggest that you look at the possibility of using a checkbox or radio button instead. If you do, you’ll have no problems using the custom validator.
However, if for some crazy reason you DO NEED to use a button and make sure the user clicks on it at least once, then just set a variable in your code and assign a value to it when the button is clicked. Check this variable’s value while doing your validation… if the variable still has the default value, then it means that the user didn’t click on it.
Hope this helps.