ASP.NET: How to get same validators control to be both client-side and server-side
        Posted  
        
            by harrije
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by harrije
        
        
        
        Published on 2010-05-20T17:44:25Z
        Indexed on 
            2010/05/20
            17:50 UTC
        
        
        Read the original article
        Hit count: 347
        
ASP.NET
|validators
Hello,
For the ASP.NET validator controls, I want to use both client-side validation for the user experience and server-side validation to guard against hackers. ASP.NET documentation leads me to believe that if EnableClientScript="True" then there will be no server-side validation if client-side validation is possible for the user agent. To get server-side validation, the documentation says use EnableClientScript="False", which bypasses client-side validation altogether.
Am I misunderstanding how the validator controls work? I ask because it seems obvious that many developers would want both client and server side validation together, and I find it hard to believe both together is not possible with one of the standard validation controls.
If I am understanding the ASP.NET documentation correctly, then I can find only two options:
- Use two validator controls exactly the same except for their ID and EnableClientScript properties. Obviously ugly for maintaining two controls almost the same. 
- Write some code behind to check if postback then invoke the Validate method on the validator group. Why write code behind if there a way to be automatic from the control? 
Is there a way to do so using a single validator control with no code behind?
Thanks in advance for your input.
© Stack Overflow or respective owner