We help IT Professionals succeed at work.

How to validate controls in a windows form only when clicking on OK button?

ipjyo
ipjyo asked
on
I have multiple controls (textboxes, comboboxes etc) and need to validate only when clicking on OK button and I dont want to validate when the control looses focus. I am using ErrorProvider to display  an error icon for each control when it fails the criteria specifed in the Validating event handler. My concern here is how to make sure to validate the controls only when clicking on the button (OK button). Also, is it possible to validate a group of controls in a panel only when the panel is visible?

Thanks for any help.
Comment
Watch Question

put the following in the aspx page to validated and add
<asp:ValidationSummary runat="server" ID="validationSummary" CssClass="notification"
    Enabled="false" Visible="false" />

<asp:RequiredFieldValidator runat="server" ID="reqValSiteId" ControlToValidate="txtSiteID"
Display="None" ErrorMessage="Site ID is a required field"></asp:RequiredFieldValidator>

Validation does not occur for panels that are not visible
Commented:
Actually I need to do the validation in a windows form. I am sorry. I should have mentioned it.

Author

Commented:
I found the solution online

Author

Commented:
I found the solution online