ASP.NET validation happens on postback

asp.netpostbackvalidation

I have a form with some input controls on a standard ASP.NET page. I use validation controls to validate the input on the server.

I noticed there are a few articles describing problems with the fact that postbacks are prevented when validation fails. My problem is kind of the opposite, i.e. postbacks are never prevented, but validation happens every time a postback occurs meaning that the form is painted over with red text every time the user changes a value in an input field (even though he is well aware that he didn't complete the form!).

Other articles at this forum argue that this behaviour is intended. Obviously the user don't want to be bothered about information telling him that he did something wrong before he pressed 'Submit' sow how do I configure the controls to only show the validation summary when the submit button is pressed and not on any postback?

Note: I only call Page.IsValid when the submit button is pressed – no where else. Thanks.

Best Answer

Try adding validationgroup property to all of your validators and a button you want to cause validation. see more: http://msdn.microsoft.com/en-us/library/ms227424.aspx Example:

    <asp:TextBox ID="TextBox1" Runat="server" ValidationGroup="First"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server" ValidationGroup="First"
    ErrorMessage="TextBox1 should not be blank" ControlToValidate="TextBox1">

    </asp:RequiredFieldValidator>
    <asp:Button ID="Submit1" Runat="server" ValidationGroup="First" Text="Submit 1" />