Client Side validation causes wrong data to be displayed in ASP.NET
I really couldn't come up with a better descriptive title for this question .. but here's the situation:
I have a form that contains multiple and different input controls .. and I have two types of validation:
This type insures that the user input doesn't violate my application's constraints (required, max length, regExp) .. and this is done on the client side using the ASP.NET Validation Controls .. and it's enforced by a server side validation.
Th开发者_Python百科is type works on a deeper level, like the database. it check if the entry is duplicate and any other check that can't be done on the UI level.
I use the ValidationSummary control to display the first type's errors, and a label for the second's type errors. I tried to test it with the JavaScript disabled and it worked fine, then I turned the JS back on and *Here comes the problem: *
I first try to raise an error on the db layer (by entering a name that already exists) and the error is displayed on the label and everything is good .. now I try to remove the name from the textbox and press the submit so I could raise a required field validator error the expected output is "This field is required" only but what I see is "the name already exists" and "This field is required".
..I think it's because when the ASP.NET RequiredValidator works, it doesn't make a postback, so the database layer will never be validated and won't even get the label cleared!
It sound like you need to add some JavaScript that hides/removes the "the name already exists" error message when the name is changed and or when trying to submit the form.
精彩评论