c fcl form control validation
Download
Skip this Video
Download Presentation
C# - FCL/Form & Control Validation

Loading in 2 Seconds...

play fullscreen
1 / 6

C# - FCL/Form & Control Validation - PowerPoint PPT Presentation


  • 50 Views
  • Uploaded on

C# - FCL/Form & Control Validation. John Kelleher. Validating Controls. Ensure correct data is input Validating event Raised when control is asked to validate contents Programmer writes event handler If contents found to be invalid programmer can notify user

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' C# - FCL/Form & Control Validation' - reuben-monroe


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
validating controls
Validating Controls
  • Ensure correct data is input
  • Validating event
    • Raised when control is asked to validate contents
    • Programmer writes event handler
    • If contents found to be invalid programmer can notify user
    • If contents found to be valid, Validated event is raised and focus is passed to next control
validating event
Validating Event
  • Only raised…
    • if control has CausesValidation property set to true

…and

    • when focus is passed to next control whose CausesValidation property set to true
  • Programmer write response: e.g. inform user of error
validating event contd
Validating Event (contd.)
  • Event handler is of type CancelEventHandler
    • this passes CancelEventArgs object
  • Event handler sets Cancel flag to true for the CancelEventArgs object if data is invalid
    • Focus does not pass to next control!
  • Event handler sets Cancel flag to false for the CancelEventArgs object if data is valid
    • Validated event is raised
example
Example

private ErrorProvider errorProvider = new ErrorProvider();

Private void textbox_Validating(object sender, CancelEventArgs e)

{

string errText = “”;

if (textbox.Text.Length == 0)

{

e.Cancel = true;

errText = “This field must not be empty”;

}

errorProvider.SetError(textbox, errText);

}

code explanation
Code explanation
  • Basic error messaging system
  • If control validation fails, focus remains with control
  • Send empty string to errorProvider to clear error message/status
  • Ensure CausesValidation property for Cancel button is set to false
    • This ensures that focus can pass to the button and the user may cancel the form
ad