1 / 0

MIS 3200 – Unit 2.2

MIS 3200 – Unit 2.2. Outline What’s the problem with bad data? Traditional solutions ASP.NET tools – Validators RequiredFieldValidator RangeValidator CompareValidator ValidationSummary. What’s the problem. BAD DATA! Bad input data Incorrect format Illegal values Illogical values

tameka
Download Presentation

MIS 3200 – Unit 2.2

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MIS 3200 – Unit 2.2 Outline What’s the problem with bad data? Traditional solutions ASP.NET tools – Validators RequiredFieldValidator RangeValidator CompareValidator ValidationSummary
  2. What’s the problem BAD DATA! Bad input data Incorrect format Illegal values Illogical values Illegal characters Illegal operations (e.g. division by zero) 03/30/2013 03/30/12 -5/03/2012 30/03/2012 ##/03/2012
  3. Traditional Solutions Data entry professionals Double entry procedures Self-checking numbers Program code
  4. Solution: Validators Controls that do error checking, such as Require an entry: Provide a credit card number Within a specified range Year of birth should be between 1900 and 2000 Compare an entry to a predetermined value Retype your password, and they should match Compare an entry the value of another control Require an email address to contain “@” and “.”
  5. How Validators Work ControlToValidate property tells the validator which TextBox to validate Placed next to the control they to validate User feedback Text ErrorMessage “Fire” (be triggered) when a button is clicked or when focus passes to another control. Remember these user feedback properties
  6. RequiredFieldValidator - RFV Typically associated with a TextBox Fires if nothing is entered in the TextBox When the validator fires it displays a message If only one of the validator’sErrorMessage and Text properties has a value then that value is displayed If both ErrorMessage and Text have values then the value of Text is displayed at the location of the validator and the value of ErrorMessage is displayed in a ValidationSummary control if there is one on the page
  7. RFV Example txtNum1 Running version before pressing Try It Running version after pressing Try It Error message color set to red No value set for Text
  8. RFV Example 2 Validation problems often need more text than what can be accommodated next to the web control. Use ValidationSummarycontrol and the ErrorMessageproperty linked to all validators on the page Design view After Running and pressing Try It
  9. CompareValidator - CV Compare an entry to a predetermined value ControlToCompare if you want to compare to another Control or the value of another control ValueToCompare to compare to a predetermined value To prevent missing data while comparing, MUST be used with a RequiredFieldValidator CV only fires if there is something to validate
  10. CV Example Allows you to chose the data type Default type is string Allows you to chose the type of comparison Default is a test for equality Allows you to set focus on the problematic data when the validator fires Recall: the Focus() method
  11. CV Example To compare to another control RequiredFieldValidatorCompareValidator Entry is not > 10 Entry is a whole number > 10 Entry is not a whole number
  12. RangeValidator - RV Similar to the CompareValidator but has a MinimumValue and a MaximumValue(instead of a ValueToCompare or FieldToCompare) Has the same Type choices as the CV Has the same SetFocusOnError option
  13. RV Example An entry is required Please enter a number in the range RFV and RV Note: this works fine for data types double and decimal
  14. Try it Out – L2.2 Make sure ASPPub is on your desktop Start VWD and open ASPPub Open the Unit2 folder under MIS3200 Click on yourLastNameU2L2.aspx file Right-click and copy Click on the Unit2 folder Right-click and paste Change the file name to yourLastNameU2L22.aspx
  15. L2.2 #2 Open the file in Design view Drop a RequiredFieldValidator to the right of your first TextBox Change the (ID) to rfvNum1 Change the ControlToValidate to txtNumber1 Change the ErrorMessage to Number 1 is required Change the Text to * Change ForeColor to red Change SetFocusOnError to true Change the Display to Dynamic
  16. L2.2 #3 Drop a CompareValidator to the right of your RequiredFieldValidator Set the (ID) to cvNumber1 Set ControlToValidate to txtNumber1 Change ErrorMessage to Number 1 must be a valid number Change Text to * Change SetFocusOnError to true Change the ForeColor to red Change Operator to DataTypeCheck Change Type to Double Change the Display to Dynamic
  17. L2.2 #4 Repeat steps 10 and 11 for the second TextBox, changing names and messages as required Drop anotherCompareValidator after the second TextBox Repeat all of step 11 again for the 2nd CV with the following differences: Set the (ID) to cvNumber2Zero Set the error message to Number 2 can’t be zero Set Operator to NotEqual Set ValueToCompare to 0(a zero) Set the ControlToValidateto txtNumber2 Do NOT set the Type (if you do delete the validator and repeat)
  18. L2.2 #5 Drop a ValidationSummary after lblOutput Change its ForeColor to red Run the page trying various combinations of values Press + with nothing in the text boxes Put a number in one text box but not the other Put non-numeric data in one text box or the other Put zero in the second text box Change the page heading to Unit 2.2 L2.2 – Simple Calculator with Validation
  19. L2.2 – Sample Output
  20. L2.2 – Final steps Open your MIS3200 home page in the MIS3200 folder Add another hyperlink for unit 2 (ID) = hlU22L22 Text = Unit 2.2 L2.2 NavigateUrl = the page you just modified Copy ASPPub back to ASPNET and submit your MIS Portfolio URL to the drop box
  21. Think About It! Why are validators important? When do you use the following: RequiredFieldValidator RangeValidator CompareValidator ValidationSummary
More Related