ASP.NET: how to get the same validator control both on client side and server side

For ASP.NET validation controls, I want to use both client-side validation for custom validation and server-side validation for protection against hackers. ASP.NET documentation allows me to believe that if EnableClientScript = "True", then server-side validation will not be performed if client-side validation is possible. To get confirmation on the server side, the documentation says that EnableClientScript = "False", which generally bypasses the client-side check.

I don’t understand how validator checks work? I ask, because it seems obvious that many developers would like to validate both client and server side together, and I find it hard to believe that both are impossible with one of the standard validation elements.

If I understand the ASP.NET documentation correctly, I can only find two options:

  • Use the two validation elements in exactly the same way, with the exception of their ID and EnableClientScript properties. Obviously ugly to maintain two controls is almost the same.

  • Write code to verify if postback then calls the Validate method in the validation group. Why write code behind if there is a way to be automatic with a control?

Is there a way to do this using a single validator validation element without code?

Thank you in advance for your entry.

+3
4

, . - CustomValidator BaseValidator, .

Page_Load() (, ). Page_Load() Page.Validate(). Page.IsValid.

ASP.NET . , , , , ViewState ( MVC), , , .

+3

, . , . - , , .

0

asp validator , postback :

Page.Validate()
if(Page.isValid)
{
     // Validation passed
}
0

Microsoft, - , .

There is much more information on how to implement validation controls in ASP.Net 2.0. Presumably, the underlying behavior has not changed in subsequent releases of ASP.Net.

0
source

Source: https://habr.com/ru/post/1746436/


All Articles