Reputation: 355
I am confused about client side and server side validation in ASP.net.
I know that client side validations validate on the client side, and asp.net validation controls
are server side controls. But if I am applying it on any server side control like <asp:textbox>
and apply RequiredFieldValidator
, it validates immediately like a client side control. All other asp validation controls validate immediately without post back to server.
So how does it work without posting back to the server?
Upvotes: 2
Views: 1231
Reputation: 79
If you use HTMLHelper in the views it will automatically insert javascript validation from e.g. the DataAnnotation of the model. Things like Required, MaxLength etc. are checked on the client-side (and on the server-side again).
Upvotes: 0
Reputation: 2501
Even though the ASP.NET server theoretically validate on the server, they will also validate on the client. From Microsoft's documentation:
If the user is working with a browser that supports dynamic HTML (DHTML), ASP.NET validation controls can perform validation using client script. Because the controls can provide immediate feedback without a round trip to the server, the user experience with the page is enhanced.
Under most circumstances, you do not have to make any changes to your page or to the validation controls to use client-side validation. The controls automatically detect if the browser supports DHTML and perform their checking accordingly. Client-side validation uses the same error display mechanism as server-side validation.
Upvotes: 2