ASP.NET Server Side

I have an ASP.NET web form that I want to validate on the client and server side using the same validation controls. I cannot find a solution for this - client validation works fine, but when I turn off javascript it ignores validation.

Help would be greatly appreciated.

Roman

+6
validation client-side server-side
source share
5 answers

You can always activate validation using the validator1.Validate() method, which will perform server-side comparisons. Check Page.IsValid to see if server side validation fails? I think you can call it through Page.Validate() .

NTN

+9
source share

Explicitly call Page.Validate () on the server side.

Or an overloaded Page.Validate (string) to target one of your validation groups.

Update:

I forgot that after running Validate (..) check the Page.IsValid property - this is for you to stop the page with if this property == false .

+15
source share

If you use standard verification elements, data is always checked on the server, even if client-side verification is specified.

See the note in this article immediately after Figure 2 :, which says:

Client-side check with double check

An interesting point is that even though the form data is checked on the client (eliminating the need for additional requests and responses from the server to verify the data), the entered data is re-checked on the server. After checking the data, the client found it valid, it is checked on the server using the same validation rules. These are the rules that you set for a complex programmer there trying to bypass the process of checking the placement of a page on the server, as if it had passed the test.

http://msdn.microsoft.com/en-us/library/aa479013.aspx

However, you can force a check on the server by calling Page.Validate ()

+3
source share

Roman

You can use the ASP.net custom validator to provide both the client and server methods for validation. Thus, if you disable js, you should still click on the server verification method. In this example, the "ClientValidate" function will be defined in the javascript block on your page, and the "ServerValidate" function will exist in your codebehind file.

 <asp:textbox id="textbox1" runat="server"> <asp:CustomValidator id="valCustom" runat="server" ControlToValidate="textbox1" ClientValidationFunction="ClientValidate" OnServerValidate="ServerValidate" ErrorMessage="*This box is not valid" dispaly="dynamic">* </asp:CustomValidator> 
+3
source share

Found the answer! The answer is to use the Page.Validate () parameter, and then to check the Page.IsValid value to verify the validation. Only using the Page.Validate () parameter did not help - the code continued and did not stop.

Thanks guys Roman

0
source share

All Articles